-
Viorel 119K Reputation points
2022-05-09T05:17:07.72+00:00 Maybe you must add 'Exit Function' after the 'Set ExecuteQuery = command.Execute()' line?
How to return ADODB.Recordset from function procedure
I am trying to create the function procedure that retrieves the data from db using ActiveX Data Object LIbrary.
This function returns the value of which type is ADODB.Recordset,but the error occurs in the statement that returns the value.
The code is as follow:
Private Function ExecuteQuery(ByVal query As String) As ADODB.Recordset
On Error GoTo Exception
Dim connection as ADODB.connection
Dim command as ADODB.command : Set command = new command
Set connection = CurrentProject.connection
command.ActiveConnection = connection
command.ActiveConnection.CursorLocation = adUseClient
command.CommandText = query
Set ExecuteQuery = command.Execute()
Exception:
DisConnect
MsgBox Err.Description
Err.Raise (Err.Number)
Exit Function
End Function
The above code causes the error in the statement:"Set ExecuteQuery = command.Execute()" ,and error number is 5
Any help on this would be appreciated.