Solved

globaly used

Posted on 2000-04-27
3
175 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

770 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