Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling code from various procedures

Posted on 1998-11-13
2
Medium Priority
?
150 Views
Last Modified: 2010-04-30
I have a basic question.  I know that if I have a public function I can call that from another sub.  Here is my problem. in about 30 different places on a form, I need to open a database and recordset(always the same).

so if I have a function that says:

Sub dbs()
Dim db As DAO.Database
Set db = OpenDatabase("S:\risk\performancesource\dashdatadelete.mdb")
Dim rs As DAO.Recordset
end sub


When I Use this sub:

private sub command1_click

dbs
set rs=db.openrecordset("name")

end sub

I get "object required"
how do I write code in a sub to recognize from another sub?

I am offering 100 points.  Please give me a good explanation and some sample code.

Thanks
0
Comment
Question by:windows1
2 Comments
 
LVL 2

Accepted Solution

by:
Poddy earned 200 total points
ID: 1444783
the scope of the database is contained within the procedure.

it is only visible within sub DBS

1. put option explicit at the start of your form module
2. you need to define the database so it is visible to the command button - so define it as
private mdb as database

and set that within sub DBS


0
 

Expert Comment

by:Ultras
ID: 1444784
Sub dbs()
 Dim db As DAO.Database
 Set db = OpenDatabase  ("S:\risk\performancesource\dashdatadelete.mdb")
 Dim rs As DAO.Recordset
end sub

private sub command1_click

 dbs
 set rs=db.openrecordset("name")
end sub

You may be declare db and rs on header module or form.

Private db as DAO.Database
private rs As DAO.Recordset
or
Public db as DAO.Database
Public rs As DAO.Recordset


Sub dbs()
 Set db = OpenDatabase  ("S:\risk\performancesource\dashdatadelete.mdb")
end sub

private sub command1_click
 dbs
 set rs=db.openrecordset("name")
end sub

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

916 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