Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / January 2005



Tip: Looking for answers? Try searching our database.

How do I make a function return an object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fred Lugar - 28 Jan 2005 01:32 GMT
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.
Fred Lugar - 28 Jan 2005 01:46 GMT
>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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.