Use function to return recordset?

  • Thread starter Thread starter Network Telephone
  • Start date Start date
N

Network Telephone

I am trying to create a public function that returns a recordset in Access
2003. Is this possible?
 
In order to provide more information, I add the following:

I may use the following in a number of modules:

strSQL = "SELECT * FROM tblContracts WHERE ContractNumber = " &
dblContractNumber

set rs = currentdb.OpenRecordset(strSQL)

I would like to move that to a public function to be called, i.e.

set rsContractData =ContractData(dblContractNumber)

This is a simplistic example, but I just need to know if it is possible.
Thanks
 
I can't guarantee it'll work (since I'm too lazy to test <g>), but try:

Function ContractData(ContractNumber As Double) As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT * FROM tblContracts " & _
"WHERE ContractNumber = " & ContractNumber

Set ContractData = CurrentDb.OpenRecordset(strSQL)

Exit Function
 
That was it (putting the "as recordset" as part of the function).

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top