SQL INSERT代码进行故障排除

时间:2015-03-13 07:00:20

标签: sql insert

我正在尝试运行此代码但收到编译错误 - INSERT ....行上的语句的预期结束。

可能出现什么问题?

Private Sub cmdInbound_Transport_Click()

Dim iProduct As Integer

iProductID = DLookup("DefaultProductID", "tblProductType", "ProductTypeID" = 1)

INSERT INTO tblGuestProduct (ProductID, GuestID,) VALUES (iProductID,tblBooking!subGuest.GuestID);

End Sub

2 个答案:

答案 0 :(得分:0)

您的Insert语句中有一个额外的逗号。试试这个,

   INSERT INTO tblGuestProduct (ProductID, GuestID) 
   VALUES (iProductID,tblBooking!subGuest.GuestID);

答案 1 :(得分:0)

删除逗号(GuestID附近)。插入行应该是这样的:

INSERT INTO tblGuestProduct (ProductID, GuestID) VALUES (iProductID,tblBooking!subGuest.GuestID);

完整代码:

Private Sub cmdInbound_Transport_Click()

Dim iProduct As Integer

iProductID = DLookup("DefaultProductID", "tblProductType", "ProductTypeID" = 1)

INSERT INTO tblGuestProduct (ProductID, GuestID) VALUES (iProductID,tblBooking!subGuest.GuestID);

End Sub