列表框由来自单独表的值填充。此列表框的值作为新记录插入到事务表中。当我尝试将列表框的值分配给我的 sql 参数时,访问抛出错误“数据类型转换错误 3421”。列表框是 txtMealType,它作为 MealID 插入,这是一个短文本字段。
Set dbs = CurrentDb
Dim vblMealType As String
txtMealType.SetFocus
vblMealType = txtMealType.Value
If (txtMealType & vbNullString) = vbNullString Then Exit Sub
Dim qdf As DAO.QueryDef
Set qdf = dbs.CreateQueryDef("", _
"PARAMETERS prmCustomerID Long, prmMealID Long, prmTransactionAmount Currency, prmTransactionDate DateTime;" & _
"INSERT INTO dbo_Transactions (CustomerID, MealID, TransactionAmount, TransactionDate) " & _
"VALUES ([prmCustomerID], [prmMealID], [prmTransactionAmount], [prmTransactionDate]) ")
qdf!prmCustomerID = txtCustomerID.Value
qdf!prmTransactionAmount = txtCharge.Value
txtCharge.SetFocus
qdf!prmTransactionDate = Format(Date, "yyyy-mm-dd")
qdf!prmMealID = vblMealType
qdf.Execute
MsgBox "Customer Charge Succesfull.", _
vbOKOnly + vbInformation
Set qdf = Nothing
Set dbs = Nothing