Jon von der Heyden
MrExcel MVP, Moderator
- Joined
- Apr 6, 2004
- Messages
- 10,907
- Office Version
- 365
- Platform
- Windows
Hi
I need some assistance with SQL syntax please. I need to insert all records in a worksheet (excl. headers in row) into an Access database. Do I really need to specify the name of every field and every entry? Is there a way to load my entire worksheet table into the Access table?
I've been toying with the below but not yet established how to pass the actual table:
I need some assistance with SQL syntax please. I need to insert all records in a worksheet (excl. headers in row) into an Access database. Do I really need to specify the name of every field and every entry? Is there a way to load my entire worksheet table into the Access table?
I've been toying with the below but not yet established how to pass the actual table:
Code:
Option Explicit
Public Sub InsertData()
'// written by Jon von der Heyden //
'// inserts data into an Access table //
'// June 2009 //
'// reference to Microsoft ActiveX Data Objects 2.x Library must be enable (where x refers to hights #)//
Dim cnAccess As ADODB.Connection
Dim sPath
Dim sConnect As String
Dim sSQL As String
'// open the upload file //
Application.Dialogs(xlDialogOpen).Show
sPath = Application.GetOpenFilename("Access Databases(*.mdb), *.mbe")
If sPath = False Then GoTo Finish
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sPath
sSQL = "INSERT INTO Workflow_TBL (*);"
Set cnAccess = New ADODB.Connection
cnAccess.ConnectionString = sConnect
cnAccess.Open
cnAccess.Execute sSQL, , adCmdText + adExecuteNoRecords
ActiveWorkbook.Close
cnAccess.Close
Set cnAccess = Nothing
Finish:
End Sub