return recordset

G

Guest

How do I return a recordset from a function?
Here is my function code and the line that calls the function. The code that
calls the function turns red and asks for an end of statement.

Calling code:
Set rs = frstRecordset lngPatientId, "patient"

Public Function frstRecordset(ByVal lngPKId As Long, strType As String) As
ADODB.Recordset

Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As New ADODB.Recordset
Dim strSQL As String

Set cnn = New ADODB.Connection
cnn.CursorLocation = adUseServer
cnn.Open fstrCnn()

Select Case strType
Case "patient"
strSQL = "SELECT v.PatientID, v.LastName" & _
" FROM Patient v" & _
" WHERE v.PatientID = " & lngPKId
Case Else
strSQL = ""
End Select

rs.Open strSQL, cnn, adOpenForwardOnly, adLockOptimistic
Set frstRecordset = rs

Thanks a million!
 
G

Guest

Tina: that got it. I could have sworn I'd tried that, but I must have had a
space off somewhere.
Have a great day.
 

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

Top