リストボックスには、別のテーブルの値が取り込まれます。このリストボックスの値は、新しいレコードとしてトランザクション テーブルに挿入されています。リストボックスの値をSQLパラメータに割り当てようとすると、「データ型変換エラー3421」というエラーが発生します。Listbox は 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