Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using module for recordset?

Status
Not open for further replies.

PB90

Technical User
Jul 11, 2005
65
US
ld like to put some recordset handling in a common module. When I try to call it from a form I get an error:
"The expression On Click you entered as the event
property setting produced the following error:
Invalid Outside Procedure.
* The expression may not result in the name of a macro,
the name of a user defined function, or [Event
Procedure].
* There may have been an error evaluating the function,
event, or macro."

My code is:

(tableHandling) module:

Option Compare Database
Option Explicit
Dim rstReqSched As ADODB.Recordset
Set rstReqSched = New ADODB.Recordset
rstReqSched.CursorLocation = adUseClient

Public Sub Open_ReqSched()
rstReqSched.Open "tblRequestSchedule", CurrentProject.Connection, adOpenStatic, adLockOptimistic
'
End Sub


Form:

Private Sub cmdSchedule_Click()
Open_ReqSched
.....other code.....
End Sub


Any suggestions?
 
Try replacing
Public Sub Open_ReqSched() with Global Sub Open_ReqSched()

See if that makes a difference.



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
I tried making it global (access dropped the word global & just left it as Sub Open_...)

This created problems with just opening the form (suddenly fields weren't recognized)

even when I tabbed by the "parameter boxes" that were created by those errors, I still got the same error.
 
Is the name of your module, the same as your procedure?
If so, change the name of either one. It's common to prefix module names with "mdl...
 
The error you are getting is simply because you are not allowed to have your Set statement outside a procedure - just as as it says.

These two lines have to go into a Sub or Function
Code:
Set rstReqSched = New ADODB.Recordset
rstReqSched.CursorLocation = adUseClient
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top