Manuel Cavero
New Member
- Joined
- Feb 17, 2018
- Messages
- 26
Hi everyone
I'm working in a code that need retrieves data from two Access databases, but unfortunately it doesn't works What the matter?
I'm working in a code that need retrieves data from two Access databases, but unfortunately it doesn't works What the matter?
VBA Code:
Dim cn as adodb.connection
Dim Qr as string
Dim rs as adodb.recordset
'Opens the conection
set cn = new adodb.connection
with cn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " & DB1Path
.CursorLocation = adUseClient
.open
end with
'Define the Query
Qr = _
"SELECT " & _
Table1 & ".Field1, " & Table1 & ".Field2, & _
Table2 & ".Field1, " & Table2 & ".Field2" & _
"FROM " & _
Table1 & " " & _
"INNER JOIN " & _
"[" & DB2Path & "]." & Table2Name & " " & _
"ON " & Table1 & ".Field1 = " & Table2 & ".Field1" & " " & _
"AND " & Table1 & ".Field1 >= #" & InitialDate & "# " & _
"ORDER BY " & Table1 & ".Field1 " & AND " & Table2 & ".Field1"
'Opens the recordset
set rs = new adodb.recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockReadOnly
.Source = iQuery
.Open
End With