0

我已经阅读了一些关于此的问答,我想我理解它,但是以真正的电枢风格,我认为我在这里遗漏了一些东西。

我正在尝试做的是一次以表格'A'的形式显示一条记录,并为用户提供按下按钮的选项,以便他们可以使用VB代码将当前查看的记录附加到表'B'以下。但是,当我按下按钮时没有任何反应,有人可以帮我澄清一下我是否理解了我所阅读的内容:

私有子 Command31_Click()

Dim PartNo, TotalQty, Description, Manufacturer, TotalCost, Category, Warehouse, BinLoc, OrderNum, DateRec, UnitCost, ReturnCode, Batch, bookinsql
PartNo = Form_LiveQfrm.[PartNo]
TotalQty = Form_LiveQfrm.[TotalQty]
Description = Form_LiveQfrm.[Description]
Manufacturer = Form_LiveQfrm.[Manufacturer]
TotalCost = Form_LiveQfrm.[TotalCost]
Category = Form_LiveQfrm.[Category]
Warehouse = Form_LiveQfrm.[Warehouse]
BinLoc = Form_LiveQfrm.[BinLoc]
OrderNum = Form_LiveQfrm.[OrderNum]
DateRec = Form_LiveQfrm.[DateRec]
UnitCost = Form_LiveQfrm.[UnitCost]
ReturnCode = Form_LiveQfrm.[ReturnCode]
Batch = Form_LiveQfrm.[Batch]
bookinsql = "INSERT INTO QStore (TextField, NumericField, TextField, TextField, NumericField, TextField, TextField, TextField, TextField, DateField, NumericField, TextField, NumericField ) VALUES ('" & Form_LiveQfrm.PartNo & "', " & Form_LiveQfrm.TotalQty & ", '" & Form_LiveQfrm.Description & "', '" & Form_LiveQfrm.Manufacturer & "', " & Form_LiveQfrm.TotalCost & ", '" & Form_LiveQfrm.Category & "', '" & Form_LiveQfrm.Warehouse & "', '" & Form_LiveQfrm.BinLoc & "', '" & Form_LiveQfrm.OrderNum & "', #" & Form_LiveQfrm.DateRec & "#, " & Form_LiveQfrm.UnitCost & ", '" & Form_LiveQfrm.ReturnCode & "', " & Form_LiveQfrm.Batch & ");"

DoCmd.RunSQL bookinsql

End Sub

我的 LiveQTemp 表的布局如下:

ID - AutoNumber
PartNo - Text
TotalQty - Number
Description Text
Manufacturer - Text
TotalCost - Number
Category - Text
Warehouse - Text
BinLoc - Text
OrderNum - Text
DateRec - Date/Time
UnitCost - Number
ReturnCode - Text
Batch - Number
4

1 回答 1

2

VALUES在您的列规范中的单词之前,您的语句中有一个额外的逗号。

改变这个:

bookinsql = "INSERT INTO LiveQTemp (TextField, NumericField, TextField, TextField, NumericField, TextField, TextField, TextField, NumericField, DateField, NumericField, TextField, NumericField,  ) VALUES (" & PartNo & ", '" & TotalQty & "', " & Description & ", " & Manufacturer & ", '" & TotalCost & "', " & Category & ", " & Warehouse & ", " & BinLoc & ", '" & OrderNum & "', '" & DateRec & "', '" & UnitCost & "', " & ReturnCode & ", '" & OrderNum & "');"

对此:

bookinsql = "INSERT INTO LiveQTemp (TextField, NumericField, TextField, TextField, NumericField, TextField, TextField, TextField, NumericField, DateField, NumericField, TextField, NumericField) VALUES ('" & PartNo & "', " & TotalQty & ", '" & Description & "','" & Manufacturer & "', " & TotalCost & ", '" & Category & "','" & Warehouse & "','" & BinLoc & "',' " & OrderNum & "', #" & DateRec & "#, " & UnitCost & ",'" & ReturnCode & "', " & Batch & ");"

此外,如果您没有收到错误,可能是因为警告设置为关闭 via: docmd.setwarnings = false并且您应该在通过 运行 statments 后重新打开它们docmd.setwarnings = true。如果您正在测试新的东西,我会让它们保持打开状态,直到它被验证,然后在声明期间将其变为 false,只需确保之后将其重新打开即可。

编辑:

你不断地用更新的信息改变你的原始问题,你不应该这样做,你应该只添加新的信息,它会使其他人和试图帮助的人感到困惑。

这是您需要的全部功能:

Private Sub Command31_Click()

    Dim PartNo, TotalQty, Description, Manufacturer, TotalCost, Category, Warehouse, BinLoc, OrderNum, DateRec, UnitCost, ReturnCode, Batch, bookinsql
    PartNo = Me.[PartNo]
    TotalQty = Me.[TotalQty]
    Description = Me.[Description]
    Manufacturer = Me.[Manufacturer]
    TotalCost = Me.[TotalCost]
    Category = Me.[Category]
    Warehouse = Me.[Warehouse]
    BinLoc = Me.[BinLoc]
    OrderNum = Me.[OrderNum]
    DateRec = Me.[DateRec]
    UnitCost = Me.[UnitCost]
    ReturnCode = Me.[ReturnCode]
    Batch = Me.[Batch]
    bookinsql = "INSERT INTO LiveQTemp (PartNo , TotalQty , Description , Manufacturer , TotalCost , Category , Warehouse , BinLoc , OrderNum , DateRec , UnitCost , ReturnCode , Batch ) VALUES ('" & PartNo & "', " & TotalQty & ", '" & Description & "', '" & Manufacturer & "', " & TotalCost & ", '" & Category & "', '" & Warehouse & "', '" & BinLoc & "', '" & OrderNum & "', #" & DateRec & "#, " & UnitCost & ", '" & ReturnCode & "', " & Batch & ");"
  '                              ^
  '                              |
  '                             Change this table to whatever table you are trying to put it in, you have listed two different ones

    DoCmd.RunSQL bookinsql

End Sub
于 2013-07-23T13:06:57.340 回答