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:33 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.
Ant - 30 Jan 2005 03:15 GMT
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.
 
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.