Sub calling Sub

krc777

Registered User.
Local time
Today, 06:35
Joined
Nov 29, 2005
Messages
70
Hello-
I have a Private sub (code behind a form) that I would like to call to a sub within the same form. The code abbreviated is as follows:

Option Compare Database

Private Sub Form_Open(cancel As Integer)
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim rst2 As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("MainQuery2")
Call getdata
end sub

Public sub getdata()
'gathers all fields needed for Private Sub
end sub

When I place the rst open statement in either sub it doesn't see it and so an 'object not found' error occurs.
 
You are not giving us a lot to work with here. However, if the called sub is providing the data to be worked with, shouldn't it be called before you set up the recordset?

If that is the case, why not just base the form on the query and not bother with the called sub at all?

Oh BTW, you don't need the "Call" word when calling a sub, just the name of the sub in code will call it.
 

Users who are viewing this thread

Back
Top Bottom