0
我在表單設計中工作,我希望用戶從組合框中選擇購買項目並鍵入單價和購買數量。用戶選擇和鍵入的所有信息將被添加到另一個表中。這裏我使用Do Until Loop逐個添加購買記錄。我嘗試了Do Until Loop。它運作良好。然而,正如我結束,這與循環Insert Into語句我收到一個語法錯誤。請幫我檢查問題出在哪裏。謝謝。訪問中的SQL插入語句的語法錯誤
我的代碼:
Private Sub Command133_Click()
Dim i As Integer
i = 1
Do Until IsNull(Me.Controls("cboPurchaseItem" & i))
Dim StrSql As String
StrSql = "Insert Into test2 (PurchaseID,
PurchaseDate,
ExpectedDeliveryDate,
Supplier,
PurchaseItem,
Unit,
PurchaseQuantity,
UnitCost,
OrderStatus,)" & _
" VALUES('" & Me!txtOrderID & "',
#" & Format(Me!txtOrderDate, "yyyy/mm/dd") & "#,
#" & Format(Me!txtDeliveryDate, "yyyy/mm/dd") & "#,
'" & Me!cboSupplierCompany & "',
'" & Me.Controls("cboPurchaseItem" & i) & "',
'" & Me.Controls("txtUnit" & i) & "',
" & CStr(Me.Controls("TxtQty" & i)) & ",
" & CStr(Me.Controls("TxtPrice" & i)) & ",
'Ordered')"
CurrentDb.Execute (StrSql)
MsgBox " You have successfully added " & i & " records to the PurchaseOrderDetail table."
i = i + 1
Loop
End Sub
我發現了一個錯誤。 OrderStatus後錯誤地輸入了一個逗號「,」。這是錯誤信息。令我驚訝的是,Me!cboSupplierCompany和Me.Controls(「cboPurchaseItem」&i)中的數據無法添加到表中空白處。 –