How to return ADODB.Recordset from function procedure

Anonymous
2022-05-09T03:18:31.607+00:00

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.

0 comments No comments
{count} votes

Accepted answer
  1. 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?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.