• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

globaly used

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
csindorf
Asked:
csindorf
  • 2
1 Solution
 
jgravelleCommented:
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
 
DalinCommented:
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
 
DalinCommented:
opps
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now