Here When I write this function in a form and try to run the program by passing the sql statement and it gives me back the correct record set and works fine...Now I want to use this function as a generic one..So I tried putting this one in class module and module then it gave me an error at the rs.source and it exited the function.please show me how to make it generic so that I can use this as a dynamic one....
Dim Connect2db As New dbConnection
Public Function fnSQL_RS(strSQL As String) As adodb.Recordset
''On Error GoTo ErrorHandler
Dim rs As adodb.Recordset
'Create and set the record set information
MsgBox strSQL
Set rs = CreateObject("ADODB.Recordset")
Set rs = New adodb.Recordset
rs.ActiveConnection = Connect2db.conn
rs.CursorLocation = adUseClient
rs.Source = strSQL
MsgBox rs.Source
rs.Open strSQL, , adOpenDynamic, adLockOptimistic
MsgBox "hello"
Set fnSQL_RS = rs
Exit Function
ErrorHandler:
Set rs = Nothing
End Function
Dim Connect2db As New dbConnection
Public Function fnSQL_RS(strSQL As String) As adodb.Recordset
''On Error GoTo ErrorHandler
Dim rs As adodb.Recordset
'Create and set the record set information
MsgBox strSQL
Set rs = CreateObject("ADODB.Recordset")
Set rs = New adodb.Recordset
rs.ActiveConnection = Connect2db.conn
rs.CursorLocation = adUseClient
rs.Source = strSQL
MsgBox rs.Source
rs.Open strSQL, , adOpenDynamic, adLockOptimistic
MsgBox "hello"
Set fnSQL_RS = rs
Exit Function
ErrorHandler:
Set rs = Nothing
End Function