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.
Hi Fred,
It looks like you're trying to assign an object to a variable without using
the SET statement.
When you pass the recordset to the function output, you have used:
- Run_SQL = recSet
This should be:
- SET Run_SQL = recSet
Whenever you assign an object to a variable (well, object variable) you must
use the SET statement otherwise you generate an error.
Values like strings, integers money, datetime etc. don't need the SET
statment.
Objects such as Recordsets, commands, forms, controls require the SET
statement.
Hope this helps
Ant
> I'm trying to write a utilities module for my project.
>
[quoted text clipped - 32 lines]
>
> Thank you in advance.