Solved

globaly used

Posted on 2000-04-27
3
173 Views
Last Modified: 2010-05-02
I have a project with just a few forms on it and on each form I have to have:

Option Explicit
'declare database variables
Public db As Database
Public rs As Recordset

Then on each form in their onload I have to add:

Private Sub Form_Load()

    'open database
    Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\tenneco.mdb")
    Set rs = db.OpenRecordset("select PCID from parts")

End Sub

Is there a simple way through a module I can set these and be able to use them on the other forms without needing to add them to each form??

Craig
0
Comment
Question by:csindorf
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
jgravelle earned 50 total points
ID: 2756996
Add the Public db as Database and the Public rs as Recordset to a module.

Then instead of having one of your forms as the Startup use a Sub Main. In this sub main you can add the code to SET the db and rs object just as you do in your forms. At the bottom of your Sub Main put in a call to startup your original startup form. This will allow all of your forms access to these objects.

Just remember to close and set to nothing before you program ends.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 2757004
You can add a module, put theese delaration in the general declaration area, then goto your project's property, change the startup item to Sub main.  In for submain, add the open database code.  then show your first form.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 2757009
opps
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now