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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a recordset to a function

Status
Not open for further replies.

ReWeFe

MIS
Joined
Mar 30, 2003
Messages
25
Location
US
This might seem to be simple to the more advanced of you out there, but I seem to have some problems with this (read: getting errors).

I have a recordset of a table, and I then want to pass the whole recordset (all the fields) to a function where I need to process the data.

Well it actually seems like I'm able to pass the recordset to a function, but then again maybe not, because I get an error when I try to read the first field:

Compile Error:
Method or data member not found

My Function is defined like this:

Private Function MyFunction(rst As DAO.Recordset)


and I try to access a particular field in the
recordset (table) like this:

myString=rst.txtSiteName


The recordset is defined like this:

Dim rstDetails As DAO.Recordset

and I open it this way where "Selection" is the SQL string:

Set rstDetails = CurrentDb.OpenRecordset(Selection)

and I call it like this:

strComplete=MyFunction(rstDetails)

What am I doing wrong here?
 
This is very confusing. From what I am reading you want to open a Table as a Recordset and loop through the records and do something with the fields of the recordset. Is this correct.

You are making this way too difficult by creating a function and calling the function, etc.

Why don't you just describe what you want to do without referencing any code. State where you are(in a form, report,etc.) and what you would like to do at a particular point in process. Then we can help you put down some VBA code that will help. Bob Scriver
 
Access uses the ! operator for items that are not defined until run time - like fields in a recordset.

myString=rst!txtSiteName

The dot is used for methods or properties that are defined as part of an object.

For example.
rst.EOF
rst.Find
 
Thanks cmmrfrds.

I actually discovered this myself late last night.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top