您好我有一个包含多个字段的数据库,我想只将信息插入其中两个字段。从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
我收到错误消息“INSERT INTO语句中的语法错误”。但我看看W3学校的SQL文档,我看到了
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');
所以语法看起来正确。我刚刚验证了表名也是正确的。那么语法错误在哪里?
答案 0 :(得分:2)
这不是您在Access中表示日期的方式
INSERT INTO Clients (FirstName, [Initial Contact])
VALUES ('Joe Sixpack', #12/1/2015#)