Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. Sub importAccessdata()
  2.  
  3. Dim cnn As ADODB.Connection
  4. Dim rs As ADODB.Recordset
  5. Dim sQRY As String
  6. Dim strFilePath As String
  7.  
  8. strFilePath = "Filename" 'Set Filename to be the Access database you are using, include the full path
  9.  
  10. Set cnn = New ADODB.Connection
  11. Set rs = New ADODB.Recordset
  12.  
  13. cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & strFilePath & ";"
  14.  
  15. sQRY = "SELECT * FROM Object" 'Replace Object with your database object name (table or query)
  16.  
  17. rs.CursorLocation = adUseClient
  18. rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
  19.  
  20. Application.ScreenUpdating = False
  21.  
  22. Sheet1.Range("A1").CopyFromRecordset rs
  23.  
  24. rs.Close
  25. Set rs = Nothing
  26.  
  27. cnn.Close
  28. Set cnn = Nothing
  29.  
  30. Exit Sub
  31.  
  32. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement