L
Laurent M
Hello, I have a little VBA function which execute a SQL
query. The function should return the relevant recordset.
But i get an error when i try to get the recordset from a
query :
My function :
***************************************
Function ImportFromdb(Query As String)
Dim DBPath As String
Dim cnt As New ADODB.Connection
Dim Rst As New ADODB.Recordset
' Database path
DBPath = "C:\Documents and
Settings\Administrateur\Bureau\MyPFE\financesoftWithData.mdb"
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=" & DBPath & ";"
Rst.Open Query, cnt, adOpenStatic
ImportFromdb = Rst
Rst.Close: cnt.Close
Set Rst = Nothing: Set cnt = Nothing
Set Rg = Nothing
End Function
***************************************
here is the part of the sub which calls the function
Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT *FROM table")
So my question is : What should my function return precisely?
Thanks !
query. The function should return the relevant recordset.
But i get an error when i try to get the recordset from a
query :
My function :
***************************************
Function ImportFromdb(Query As String)
Dim DBPath As String
Dim cnt As New ADODB.Connection
Dim Rst As New ADODB.Recordset
' Database path
DBPath = "C:\Documents and
Settings\Administrateur\Bureau\MyPFE\financesoftWithData.mdb"
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=" & DBPath & ";"
Rst.Open Query, cnt, adOpenStatic
ImportFromdb = Rst
Rst.Close: cnt.Close
Set Rst = Nothing: Set cnt = Nothing
Set Rg = Nothing
End Function
***************************************
here is the part of the sub which calls the function
Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT *FROM table")
So my question is : What should my function return precisely?
Thanks !