Force user to enter data

C

Chris

I have 2 fields, the first field (text field) named
txtFinding can have only 3 response Yes, No, N/A. The
second field (memo field) is named memComments.

If the user enters a No in the txtFinding and no comment
in the memComments field I want a message to pop up that
says "You entered a No, you MUST enter a comment!!" and
then go back to the memComments field to make the user
enter a comment.
 
J

John Vinson

I have 2 fields, the first field (text field) named
txtFinding can have only 3 response Yes, No, N/A. The
second field (memo field) is named memComments.

If the user enters a No in the txtFinding and no comment
in the memComments field I want a message to pop up that
says "You entered a No, you MUST enter a comment!!" and
then go back to the memComments field to make the user
enter a comment.

Use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!txtFinding = "No" And IsNull(Me!memComments) Then
MsgBox "<chiding message>"
Cancel = True
Me!memComments.SetFocus
End If
End Sub
 
C

Chris

John, It did not work. Here is what I put in.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If fsubFinishedAudit![txtFinding] = "No" And IsNull
(fsubFinishedAudit![memComments]) Then
MsgBox "<You entered a No, you MUST enter a comment!!>"
Cancel = True
fsubFinishedAudit!memComments.SetFocus
End If

End Sub
 
J

John Vinson

John, It did not work. Here is what I put in.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If fsubFinishedAudit![txtFinding] = "No" And IsNull
(fsubFinishedAudit![memComments]) Then
MsgBox "<You entered a No, you MUST enter a comment!!>"
Cancel = True
fsubFinishedAudit!memComments.SetFocus
End If

End Sub

I gather that fsubFinishedAudit is a Subform? If so, you need to put
the code on fsubFinishedAudit's BeforeUpdate event and replace
fsubFinishedAudit! with Me!, or else with
Forms!mainformname!subformname.Form! (where subformname is the name of
the Subform control containing the form, which might or might not be
fsubFinishedAudit).
 
C

Chris

Thanks, got it.

-----Original Message-----
John, It did not work. Here is what I put in.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If fsubFinishedAudit![txtFinding] = "No" And IsNull
(fsubFinishedAudit![memComments]) Then
MsgBox "<You entered a No, you MUST enter a comment!! "
Cancel = True
fsubFinishedAudit!memComments.SetFocus
End If

End Sub

I gather that fsubFinishedAudit is a Subform? If so, you need to put
the code on fsubFinishedAudit's BeforeUpdate event and replace
fsubFinishedAudit! with Me!, or else with
Forms!mainformname!subformname.Form! (where subformname is the name of
the Subform control containing the form, which might or might not be
fsubFinishedAudit).


.
 

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