I am writing a macro that will run from an excel workbook and export out one of the ListObjects to my access file.
I have this VBA code at the moment:
Sub AccessImport()
' Create connection
Dim Path As String
Dim conn As Object
Dim connectstr As String
Dim recordset As Object
Dim strSQL As String
Path = "P:\CALIBRE-YSP Implementation\11 General\CDM Database"
Set conn = CreateObject("ADODB.Connection")
connectstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Path & "\CDM_Database_DataOnly.mdb;"
strSQL = "SELECT * INTO DeliverablesLivesheet FROM [Excel 8.0;HDR=YES;DATABASE=P:\CALIBRE-YSP Implementation\11 General\CDM Database\CDMv2 - Development.xlsm].[DeliverablesImport];"
conn.Open connectstr
Set recordset = conn.Execute(strSQL)
recordset.Close
Set recordset = Nothing
conn.Close
Set conn = Nothing
End Sub
It is supposed to take a ListObject from Excel then transfer the data to a new access table, overwriting the old one.
It throws an error when it tries to execute the SQL:
strSQL = "SELECT * INTO DeliverablesLivesheet FROM [Excel 8.0;HDR=YES;DATABASE=P:\CALIBRE-YSP Implementation\11 General\CDM Database\CDMv2 - Development.xlsm].[DeliverablesImport];"
So I guess something is wrong with the SQL?
I can't seem to work it out though
Thanks
strSQL = "..."
would throw an error. At that point, the string hasn't been submitted to the db engine, so it wouldn't matter whether or not it's a valid SQL statement. As long as it's any valid string, it shouldn't throw an error. What is the full error message? – HansUp Apr 3 at 5:22