Require Entry in Text Box

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!
 
G

Guest

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
 
M

Marshall Barton

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.
 

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