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!
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!