每当我点击此命令时,我都会收到错误消息。我试图将交易历史记录放在TransactionNo和Earnings的字段上,而其他字段仅用于库存。
Private Sub Command1_Click()
Dim earnings As Double
earnings = txtCash - txtChange
ConnectDB
rs.Open "Select TransactionNo, Earnings from Table2", db, 3, 3
rs.AddNew
rs(0) = txtNumber 'rs(1) is an auto number
rs(2) = txtProduct 'Here i got an error, it says Item cannot be found in the 'collection corresponding to the requested name or ordinal
rs(3) = txtStockLeft
rs(4) = txtPricePiece
rs(5) = txtExpiry
rs(6) = earnings
rs.Update
Set rs = Nothing
db.Close: Set rs = Nothing
LoadData1
ListView2.ListItems.Clear
LoadData
这里有什么问题?
答案 0 :(得分:0)
只需将代码rs(2) = txtProduct
更改为rs(1) = txtProduct
根据我说的改变代码时,你不会在该行上出错。
但是你会在下面找到错误
rs(3) = txtStockLeft
rs(4) = txtPricePiece
rs(5) = txtExpiry
这是因为您的选择查询仅返回2列Select TransactionNo, Earnings from Table2
。您需要包含其他相关列。