2013-11-19 5 views
1

Код должен включать новую запись в таблицу транзакций. Однако это приводит к компиляции erro «Недопустимое использование свойства» в строке SET QDF. Что может вызвать такую ​​ошибку?MS Access/SQL: недопустимое использование свойства

Private Sub cmdCharge_Click() 
Dim vblMealType As String 
Dim vblMealQual As String 
Dim dbs As DAO.Database 


If txtMealID.ItemsSelected.Count = 0 Then 

     MsgBox "Please Select a Meal Type", _ 
       vbOKOnly + vbInformation 
Else 



MsgBox "Customer Charge Succesfull.", _ 
       vbOKOnly + vbInformation 
Set dbs = CurrentDb 
Dim QDF As DAO.QueryDef 
QDF = dbs.CreateQueryDef("", _ 
     "PARAMETERS prmCustomerID Text(255), prmMealID Text(255), prmTransactionAmount Currency, prmTransactionDate Text(255);" & _ 
     "INSERT INTO dbo_Transactions (CustomerID, MealID, TransactionAmount, TransactionDate) " & _ 
     "VALUES ([prmCustomerID], [prmMealID], [prmTransactionAmount], [prmTransactionDate])") 


QDF!prmCustomerID = txtCustomerID.Value 
QDF!prmMealID = txtMealID.Value 
QDF!prmTransactionAmount = txtCharge.Value 
QDF!prmTransactionDate = Date 
QDF.Execute dbFailOnError 
MsgBox "Customer Charge Succesfull.", _ 
       vbOKOnly + vbInformation 

Set QDF = Nothing 
Set dbs = Nothing 

DoCmd.OpenForm "Charge Form" 
DoCmd.Close acForm, Me.Name 

End If 
End Sub 

ответ

0

Поскольку QDF является изменяемый объект, вы должны использовать ключевое слово Set при присвоении значения к нему.

Set dbs = CurrentDb 
Dim QDF As DAO.QueryDef 
Dim strInsert As String 
strInsert = "PARAMETERS prmCustomerID Text(255), prmMealID Text(255), prmTransactionAmount Currency, prmTransactionDate Text(255);" & _ 
     "INSERT INTO dbo_Transactions (CustomerID, MealID, TransactionAmount, TransactionDate) " & _ 
     "VALUES ([prmCustomerID], [prmMealID], [prmTransactionAmount], [prmTransactionDate])" 
Debug.Print strInsert 
Set QDF = dbs.CreateQueryDef("", strInsert) 
Смежные вопросы