访问错误消息:“参数太少。期待1.“ [英] acess error message:"too few parameters. Expect 1."
问题描述
我的朋友们:
我是办公室访问的新手。我正在使用Access 2013开发成品库存。我想使用表格来显示成品的实时库存水平。如果产品是新生产的,则会为此产品创建一行,否则此产品的
数量将添加到现有商品中。
I am new in office access. I am developing a finished product inventory by using access 2013. I want to use a table to show the real time stock level of finished product. If the product is newly produced, it will create a row for this product otherwise the quantity of this product will add to the existed item.
这是我的代码
Private Sub Command92_Click()
Dim RC As Integer
RC = DCount("[Finished_Product]", "tbl_Finished_Product_Inventory", "[Finished_Product]= " & Me!cboFinishedProduct & " AND [LotNo]= '" & Me!cboFinishedProduct.Column(5) & " '")
If RC = 0 Then
CurrentDb.Execute " INSERT INTO tbl_Finished_Product_Inventory(Finished_Product, LotNo, Quarantined_Qty, Stock_Unit, LastUpdate) VALUES (" & Me!cboFinishedProduct & ", '" & Me!cboFinishedProduct.Column(5) & "', " & CStr(Me!txtLiberatedQty) & ",'" & Me!txtUnit & "', Now())"
Else
CurrentDb.Execute " UPDATE tbl_Finished_Product_Inventory SET Quarantined_Qty = Qurantined_Qty + " & CStr(Me!txtLiberatedQty) & ", LastUpdate = Now() WHERE Finished_Product = " & Me!cboFinishedProduct & " AND LotNo = '" & Me!txtLot & "' "
End If
MsgBox (" You have successfully updated ONE RECORD in tbl_Finished_Product_Inventory")
End Sub
如果是产品新的这个代码运作良好。但是,如果是一个存在的批次,我收到一条错误消息,说"参数太少?预期1" 。请帮助我,给我一个理想的错误。
If it is a product with new lot this code works well. But If is an existed lot, I got an error message saying "too few parameters? Expected 1" . Please help me and give me an ideal where I am wrong.
谢谢
推荐答案
我会按如下方式调试:
I would debug this as follows:
如果 RC = 0
然后
dim sql as string
sql = " INSERT INTO tbl_Finished_Product_Inventory(Finished_Product,LotNo,Quarantined_Qty,Stock_Unit,LastUpdate)VALUES(<
& Me ! cboFinishedProduct
& ",' "
& 我 ! <跨度> cboFinishedProduct 跨度> <跨度> 跨度> <跨度>列跨度> <跨度>(跨度> <跨度> 5 跨度> <跨度>)跨度> <跨度>
& "',"
& CStr ( 我 ! txtLiberatedQty )
& ",'" &
我 ! txtUnit &
"',Now())"
CurrentDb 。 执行 sql,dbFailOnError
If RC = 0
Then
dim sql as string
sql = " INSERT INTO tbl_Finished_Product_Inventory(Finished_Product, LotNo, Quarantined_Qty, Stock_Unit, LastUpdate) VALUES ("
& Me!cboFinishedProduct
& ", '"
& Me!cboFinishedProduct.Column(5)
& "', "
& CStr(Me!txtLiberatedQty)
& ",'" &
Me!txtUnit &
"', Now())"
CurrentDb.Execute sql, dbFailOnError
然后在执行行和立即窗口中放置一个断点:
?sql
你看到了吗?它?实际上有两个错误:不匹配的单引号和日期时间值需要包含在#-signs中。
我还添加了dbFailOnError;如果发生错误,您不希望出现运行时错误。
Then put a breakpoint on the Execute line and in the Immediate window:
?sql
Do you see it?
There are actually two errors: mismatched single quotes and datetime values need to be wrapped in #-signs.
I also added dbFailOnError; it's exceedingly rare that you do not want a runtime error if an error occurs.
这篇关于访问错误消息:“参数太少。期待1.“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!