Require Entry in Text Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a continuous form where I want to require entry in a text box if the
value of another control is set to False. (It's for auditing - if the audit
was nonconforming, then the user must enter a corrective action.) I have the
code move the focus to the text box when the other control is updated to
False, but I cannot figure out how to require the user to enter anything into
the text box before they can click/tab out of the field. I have attempted
several versions of code and have been able to make a message box appear, but
I still cannot force the user to stay on the text box control in the current
record. Any help would be greatly appreciated!
 
Simplest way is to use the Before Update event of the form to check for the
condition:

Private Sub form_BeforeUPdate(Cancel As Integer)

If Me.txtConforming = False Then
If IsNull(Me.txtCorrectiveAction) Then
MsgBox "Corrective Action Required for Non Conforming Audit"
Cancel = True
Me.txtCorrectiveAction.SetFocus
Exit Sub
End If
End If
 
BenL712 said:
I have a continuous form where I want to require entry in a text box if the
value of another control is set to False. (It's for auditing - if the audit
was nonconforming, then the user must enter a corrective action.) I have the
code move the focus to the text box when the other control is updated to
False, but I cannot figure out how to require the user to enter anything into
the text box before they can click/tab out of the field. I have attempted
several versions of code and have been able to make a message box appear, but
I still cannot force the user to stay on the text box control in the current
record.

Use the text box's BeforeUpdate event and set Cancel = True
if the value is Null.
 
Back
Top