I'm trying to write a utilities module for my project.
I want the module to contain a function to accept a SQL statement as a
parameter and return an ADO recordset object.
Everything works fine until I try to return the recordset to the
calling function. The message box shows the right value for the first
field in the record set.
When I add a line to return the recordset "Run_SQL = recSet" I get an
error message that highlights this line of code and says "Invalid use
of property."
Option Explicit
Dim db_file As String
Dim SQLstmt As String
Dim dbConn As ADODB.Connection
Dim recSet As ADODB.Recordset
Dim strClient As String
Public Function Run_SQL(SQLs As String) As ADODB.Recordset
Make_Connection
SQLstmt = SQLs
Run_SQL_Stmt
MsgBox "Run_SQL function " & recSet.Fields(0)
Run_SQL = recSet
End Function
Please tell me how to correct this.
Thank you in advance.
>I'm trying to write a utilities module for my project.
>
[quoted text clipped - 32 lines]
>
>Thank you in advance.
I found a web site that said you have to use the set command and then
it worked fine.
Set Run_SQL = recSet
When is the Set command required vs. not required?
Thanks again.
Fred
Ralph - 28 Jan 2005 16:02 GMT
> >I'm trying to write a utilities module for my project.
> >
[quoted text clipped - 43 lines]
>
> Fred
Whenever you are making an assignment to, or initializing an 'Object'
Reference Variable.
-ralph