Force data entry if criteria is met

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

Chris Kudron

I have 2 fields, Finding and Comments. If the person
enters No. in findings I want to force them to put
something in the comments field. If they try and tab out
I want a message to come up that says they have to enter
something, they click OK and it goes back to the Comments
box until something is entered. I think it goes in the
afterupdate of the comments field. How do I do this?
 
Chris,

Actually you are better off in the BeforeUpdate event which
has a Cancel option to just leave the user there until they
meet the criteria. Substituting your control names you could
do something like this...

Sub Form_BeforeUpdate(Cancel as Integer)

If Len(Me!Finding) > 0 Then
msgbox "Since you entered a Finding you must now enter a
Comment!"
Cancel = True
End If

End Sub

Gary Miller
Sisters, OR
 
You forgot to check if something was already entered.

If Len(Me!Finding) > 0 and Len(Me!Comments) = 0 Then
msgbox "Since you entered a Finding you must now enter a
Comment!"
Cancel = True
End If

What if a comment is entered without a finding? Just another thing to think
about.

Kelvin
 
Good catch Kelvin!

Gary Miller

Kelvin said:
You forgot to check if something was already entered.

If Len(Me!Finding) > 0 and Len(Me!Comments) = 0 Then
msgbox "Since you entered a Finding you must now enter a
Comment!"
Cancel = True
End If

What if a comment is entered without a finding? Just another thing to think
about.

Kelvin
 
Chris,

If this is a Yes/No field, which you hadn't mentioned, you
would need to revise it to this...

If Me!Finding) = True and Len(Me!Comments) = 0 Then
etc....

Gary Miller
 
Back
Top