Validate

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have the following code and get an error Run time error
2471. The expression you entered as a query parameter
produced this error: The object doesn't contain the
Automation object 'Forms!fsubFinishedAudit!
TblFinishedAudit_txtQuestionNumber.'

The code works fine in the sub form but when I try and use
it in the main form I get the above error. Here is the
code.

Private Sub txtPlant_BeforeUpdate(Cancel As Integer)
Dim iAns As Integer
If Not IsNull(DLookup("Forms![fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber]", "TblFinishedAudit",
"[TblFinishedAudit]![txtQuestionNumber] = Forms!
[fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber]")) Then
iAns = MsgBox("This Question has already been answered!
Use it anyway?", vbYesNo)
If iAns = vbNo Then
Cancel = True
Forms![fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber].Undo
End If
End If


End Sub
 
Chris,

The exclamation mark between container name Forms and the
form name is correct, but between form name and field name
you should be using a dot separator instead of an
exclamation mark.

Nikos
-----Original Message-----
I have the following code and get an error Run time error
2471. The expression you entered as a query parameter
produced this error: The object doesn't contain the
Automation object 'Forms!fsubFinishedAudit!
TblFinishedAudit_txtQuestionNumber.'

The code works fine in the sub form but when I try and use
it in the main form I get the above error. Here is the
code.

Private Sub txtPlant_BeforeUpdate(Cancel As Integer)
Dim iAns As Integer
If Not IsNull(DLookup("Forms![fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber]", "TblFinishedAudit",
"[TblFinishedAudit]![txtQuestionNumber] = Forms!
[fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber]")) Then
iAns = MsgBox("This Question has already been answered!
Use it anyway?", vbYesNo)
If iAns = vbNo Then
Cancel = True
Forms![fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber].Undo
End If
End If


End Sub
.
 
Chris said:
I have the following code and get an error Run time error
2471. The expression you entered as a query parameter
produced this error: The object doesn't contain the
Automation object 'Forms!fsubFinishedAudit!
TblFinishedAudit_txtQuestionNumber.'

The code works fine in the sub form but when I try and use
it in the main form I get the above error. Here is the
code.

Private Sub txtPlant_BeforeUpdate(Cancel As Integer)
Dim iAns As Integer
If Not IsNull(DLookup("Forms![fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber]", "TblFinishedAudit",
"[TblFinishedAudit]![txtQuestionNumber] = Forms!
[fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber]")) Then
iAns = MsgBox("This Question has already been answered!
Use it anyway?", vbYesNo)
If iAns = vbNo Then
Cancel = True
Forms![fsubFinishedAudit]!
[TblFinishedAudit_txtQuestionNumber].Undo
End If
End If
End Sub

The DLookup has inappropriate quotes. I'm not sure what
you're trying to do, but you might to try using something
more like this:

DLookup(Forms![fsubFinishedAudit]![TblFinishedAudit_txtQuestionNumber],
"TblFinishedAudit", "txtQuestionNumber = " &
Forms![fsubFinishedAudit]![TblFinishedAudit_txtQuestionNumber])
 
Back
Top