Hi.
I not acutely proficient when it comes to programming but upon research I was able to come accross the below code that sometwhat fit my purpose. The code copys data in a TABLE in access and paste in an excel worksheet called Sheet1 starting from cell b1. Is it possible to have the code repeat this process by copying data from several tables in access (say TAbLE2, TABLE3, ...) and paste in the same workbook on Sheet2, Sheet3...? The code is run from excel.
I will glady appreciate the help
I not acutely proficient when it comes to programming but upon research I was able to come accross the below code that sometwhat fit my purpose. The code copys data in a TABLE in access and paste in an excel worksheet called Sheet1 starting from cell b1. Is it possible to have the code repeat this process by copying data from several tables in access (say TAbLE2, TABLE3, ...) and paste in the same workbook on Sheet2, Sheet3...? The code is run from excel.
I will glady appreciate the help
Code:
Sub GetData()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
strFilePath = "C:\DatabaseFolder\MyDatabase.accdb"
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
Sheet1.Range("DataRange").ClearContents
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";"
sQRY = "SELECT * FROM TABLE1"
rs.CursorLocation = adUseClient
rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet1.Range("B2").CopyFromRecordset rs
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub
Last edited by a moderator: