Someone very kindly showed me this concept, and function
Which works very nicely, but I'm now trying to use this with a Connction to another db and run into a few problems.
I'm opening the db with
where BackendFileSpec is the path & name of the other db. Then I'm attempting to call the function with
In the function I've changed 'As DAO.Recordset' to ' As ADODB.Recordset
' (although it did not capitalize) and 'Currentdb' to 'cnn'.
I'm getting error 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.' so suspect it's all wrong!
Any help appreciated.
Code:
Function Matches(L As String, C As String) As DAO.Recordset
Const sql As String = _
"SELECT t.* " & _
"FROM tblMain As t " & _
"WHERE t.Lake = p0 " & _
"AND t.Region = p1 "
With CurrentDb.CreateQueryDef("", sql)
.Parameters("p0") = L
.Parameters("p1") = C
Set Matches = .OpenRecordset
.Close
End With
End Function
Which works very nicely, but I'm now trying to use this with a Connction to another db and run into a few problems.
I'm opening the db with
Code:
Sub OpenBackend() 'Access
Set cnn = New adodb.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & BackendFileSpec
cnn.Open
End Sub
where BackendFileSpec is the path & name of the other db. Then I'm attempting to call the function with
Code:
OpenBackend
Dim rx As adodb.Recordset
Set rx = Matches(CStr(Lake), CStr(Region))
In the function I've changed 'As DAO.Recordset' to ' As ADODB.Recordset
' (although it did not capitalize) and 'Currentdb' to 'cnn'.
I'm getting error 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.' so suspect it's all wrong!
Any help appreciated.