question

ntsol-5133 avatar image
0 Votes"
ntsol-5133 asked Viorel-1 answered

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.

office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Maybe you must add 'Exit Function' after the 'Set ExecuteQuery = command.Execute()' line?


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for helping.
I solved the problem, adding 'Exit Function'.
I learned a lot.
I'm grateful to you.

0 Votes 0 ·