Hi I have a database with several fields and I want to insert information only into two of them. To feed this information from excel;
Sub testing()
On Error GoTo errorhandler
'
' testing Macro
'
' Keyboard Shortcut: Ctrl+d
'
Dim cn As Object
Dim rs As Object
Dim strSql As String
Dim strConnection As String
Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\Path\Here\Database.accdb"
strSql = "INSERT INTO Clients (FirstName, Initial Contact) VALUES ('Joe Sixpack', 12/1/2015);"
cn.Open strConnection
Set rs = cn.Execute(strSql)
' rs.Close
cn.Close
Exit Sub
errorhandler:
MsgBox (Err.Number & " " & Err.Description)
End Sub
I receive an error message "syntax error in INSERT INTO statement". But I look at the documentation of SQL on W3 schools and I see
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');
So the syntax looks correct. I've just verified that the table names are also correct. So where is the syntax error?