return recordset

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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.
 
Back
Top