Why is this VBA Code generating this error message?
Run-time error -2147217904 (80040e10)
Automation error
Unspecified error
Run-time error -2147217904 (80040e10)
Automation error
Unspecified error
Code:
Sub Data_Push()
'This function pushes data from an Excel spreadsheet
'into a SQL Server database by pressing a button in Excel.
'Created/modified from various code samples
'--------------------------------------------------------------------------------
Dim OLEString As String
OLEString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ActiveWorkbook.Path & "\" & ActiveWorkbook.Name & ";" & _
"Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"
'...Maybe provider should be "sqloledb"?
'OLEString = "Provider=sqloledb;"
'MsgBox OLEString
'...Maybe OLE string should be an ODBC string?
Dim ODBCString As String
ODBCString = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;" & _
"Dbq=" & ActiveWorkbook.Path & "\" & ActiveWorkbook.Name & ";" & _
"DefaultDir=" & ActiveWorkbook.Path & ";"
'MsgBox ODBCString
'--------------------------------------------------------------------------------
Dim SQLString As String
SQLString = "INSERT INTO [ODBC;Driver={SQL Server};" & _
"SERVER=ESSPITSRV01;DATABASE=Intranet;" & _
"Trusted_Connection=yes;].TestTempTable (col1)" & _
" VALUES ('test')"
'...Test literal value first, then push Excel sheet data with select statement
'" SELECT (col1) FROM [testpage$];"
'MsgBox SQLString
'--------------------------------------------------------------------------------
Dim con As Object
Set con = CreateObject("ADODB.Connection")
con.Open OLEString
con.Execute SQLString
con.Close
End Sub