Validate

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
 
N

Nikos Yannacopoulos

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
.
 
M

Marshall Barton

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])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top