Option Explicit
Public stcon As String
Sub Get_Data()
Dim stcon As String
stcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\<File Path>
;Persist Security Info=False"
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stSQL As String
Dim stPrm1 As String, stPrm2 As String
Dim j As Long
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets(1)
With wsSheet
For j = 2 To .Range("A65536").End(xlUp).Row
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
cnt.ConnectionString = stcon
stPrm1 = .Cells(j, 1).Value
stPrm2 = .Cells(j, 2).Value
stSQL = "SELECT dbo_Name1.COMPANY,
dbo_Subscriptions2.BILL_AMOUNT, dbo_Subscriptions2.PAYMENT_AMOUNT,
dbo_Subscriptions2.ADJUSTMENT_AMOUNT, dbo_Subscriptions2.PAYMENT_DATE,
dbo_Subscriptions2.BILL_DATE, dbo_Subscriptions2.BILL_BEGIN FROM C:\Documents
and Settings\TEST DATABASE.accdb.dbo_Name1, C:\Documents and Settings\TEST
DATABASE.accdb`.dbo_Subscriptions2 dbo_Subscriptions2 "
stSQL = stSQL & "WHERE dbo_Subscriptions2.ID = '" & stPrm1 & "'"
stSQL = stSQL & " AND dbo_Name1.ID = dbo_Subscriptions2.ID '" &
stPrm2 & "';"
cnt.ConnectionString = cnt
cnt.Open
With rst
.CursorLocation = adUseClient
.Open stSQL, cnt, adOpenStatic, adLockReadOnly
.ActiveConnection = Nothing
End With
.Cells(j, 3).CopyFromRecordset rst
rst.Close
Set rst = Nothing
cnt.Close
Set cnt = Nothing
Next j
End With
End Sub
Try an office forum or an answer forum
http://social.answers.microsoft.com/Forums/en-US/categories
Success
Cor
"gceiley" <gce...@discussions.microsoft.com> wrote in message
news:17AA879A-1086-4540...@microsoft.com...