pedie
Well-known Member
- Joined
- Apr 28, 2010
- Messages
- 3,875
Hi, i need simple VBA to import data from access file path "E:\Personal_Files\Access\Database2.accdb", table name "Datas", all fields to sheet one.
Thanks in advance
Pedie
I tried below code with above path and errors....unrecognized format....
Please advice...
Thanks in advance
Pedie
I tried below code with above path and errors....unrecognized format....
Please advice...
Code:
[/FONT]
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
strFilePath = "E:\Personal_Files\Access\Database2.mdb"
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
Sheet1.Range("A1").ClearContents
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";"
sQRY = "SELECT Datas.* FROM Datas"
rs.CursorLocation = adUseClient
rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet1.Range("A1").CopyFromRecordset rs
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
Last edited: