[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

globaly used

Posted on 2000-04-27
3
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
jgravelle earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

656 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