2013-11-28 119 views
0

似乎很容易,但我沒有辦法實在不行,它給了錯誤味精(語法錯誤INSERT INTO語句中)..SQL INSERT INTO語句不行VBA

Call Connect_to_db 

strSQL = "INSERT INTO Table2 (Name, StaffNumber , Title , Number , ext , Nationalty , Section , Sector , Side , Department , Civil , Job_title) Values ('" & addName.TExt & "', " & Val(addStaffID.TExt) & ", '" & addTitle.TExt & "', " & Val(addNumber.TExt) & " , " & Val(addExt.TExt) & " , '" & addNation.TExt & "', '" & addSection.TExt & "', '" & addSector.TExt & "', '" & addSide.TExt & "', '" & addDept.TExt & "' , " & Val(addCivil.TExt) & ", '" & addJob.TExt & "' )" 
Debug.Print strSQL 
cn.Execute strSQL 

MsgBox ("Data Added to the Database") 

Call Close_db 

所有數據類型的文本除(StaffNumber,分機,號碼,民用)號碼

我相信我需要每個之前的修剪,但我不認爲這是問題的原因。

+0

你能分享生成的SQL? ''Debug.Print strSQL' – Sam

+0

INSERT INTO Table2(Name,StaffNumber,Title,Number,Ext,Nationalty,Section,Sector,Side,Department,Civil,Job_title)Values('Ali',55,'Mr.',54654, 454,'KUW','風險','COM','市場',1251,'主管')@Sam – SQB

+2

國籍或國籍? – 2013-11-28 08:24:23

回答

0

您缺少VALUES子句中的Job_title值。你也錯過了DepartmentCivil列。

這是應該的:

INSERT INTO Table2 
    ([NAME], 
    StaffNumber, 
    Title, 
    Number, 
    ext, 
    Nationalty, 
    Section, 
    Sector, 
    Side, 
    Department, 
    Civil, 
    Job_title) 
VALUES 
    ('" & addName.TExt & "', 
    " & Val(addStaffID.TExt) & ", 
    '" & addTitle.TExt & "', 
    " & Val(addNumber.TExt) & ", 
    " & Val(addExt.TExt) & ", 
    '" & addNation.TExt & "', 
    '" & addSection.TExt & "', 
    '" & addSector.TExt & "', 
    '" & addSide.TExt & "', 
    '" & addDept.TExt & "', 
    " & Val(addCivil.TExt) & ", 
    ADD_JOB_TITLE_VALUE_HERE) 
+0

我更新了代碼..但是同樣的錯誤 – SQB