在访问

时间:2016-06-12 17:25:47

标签: sql ms-access textbox

我试图通过sql insert into statement将表单信息添加到表中。不幸的是,我收到了语法错误消息。请帮我查一下格式。 我的代码是:

Private Sub cmdSaveRecord_Click()
  Dim StrSql As String
   StrSql = "Insert Into test2 (PurchaseDate, SupplierCompany, PurchaseItem, Unit, PurchaseQuantity, UnitCost, ExtendedPrice)" & _
          " VALUES(#" & Format(Me!txtOrderDate, "yyyy/mm/dd") & "#, '" & Me!cboSupplierCompany & "', '" & Me!cboPurchaseItem1 & "', '" & Me!txtUnit1 & "'," & CStr(Me!txtQty1) & ", ," & CStr(Me!TxtPrice1) & ", " & CStr(Me!TxtTotal1) & " )"
CurrentDb.Execute (StrSql)
MsgBox " You have successfuly add one record to PurchaseOrderDetail table."

End Sub

1 个答案:

答案 0 :(得分:1)

中有空列
  "Insert Into test2 (
    PurchaseDate
    , SupplierCompany
    , PurchaseItem
    , Unit
    , PurchaseQuantity
    , UnitCost
    , ExtendedPrice
    )" & _
      " VALUES(
      #" & Format(Me!txtOrderDate, "yyyy/mm/dd") & "#
      , '" & Me!cboSupplierCompany & "'
      , '" & Me!cboPurchaseItem1 & "'
      , '" & Me!txtUnit1 & "'
      ," & CStr(Me!txtQty1) & "
      ,                       <----- here
      ," & CStr(Me!TxtPrice1) & "
      , " & CStr(Me!TxtTotal1) & " )"

将其删除

  "Insert Into test2 (
    PurchaseDate
    , SupplierCompany
    , PurchaseItem
    , Unit
    , PurchaseQuantity
    , UnitCost
    , ExtendedPrice
    )" & _
      " VALUES(
      #" & Format(Me!txtOrderDate, "yyyy/mm/dd") & "#
      , '" & Me!cboSupplierCompany & "'
      , '" & Me!cboPurchaseItem1 & "'
      , '" & Me!txtUnit1 & "'
      ," & CStr(Me!txtQty1) & "
      ," & CStr(Me!TxtPrice1) & "
      , " & CStr(Me!TxtTotal1) & " )"