Text box required if Check box is selected on Form (1 Viewer)

IstyDawn

New member
Local time
Today, 04:25
Joined
Feb 25, 2020
Messages
7
Hi!
I am working on a new database and the manager has a request that I am having issue with. There are 3 check boxes each with a corresponding text box. When a user marks the check box "yes" on the form, the text box needs to become required.

Check boxes:
Coder_Issue
Physician_Issue
Dept_Clinic_Issue

Text boxes:
Coder
Physician
Dept_Clinic

I have tried various things but I end up getting the msgbox as soon as the check box is selected (or it does nothing). It wants the text field entered before the box is checked. What I need is for it to give the message when the user clicks save and there is a check box marked but the text box is blank... Help???
Also- I showed the SetFocus line below but I cannot use it without getting a run-time error "2108'

This is the most recent attempt.

Private Sub Physician_Issue_BeforeUpdate(Cancel As Integer)
If Me.Physician_Issue.Value And Len(Trim(Me.Physician.Value & vbNullString)) = 0 Then
MsgBox "Physician Field Required"
Cancel = True
Me.Physician.SetFocus
End If
End Sub
 

IstyDawn

New member
Local time
Today, 04:25
Joined
Feb 25, 2020
Messages
7
See this related, older post by Pat Hartman for info.
Hope it's helpful.

Thanks, now I understand why it was clearing the check box! I am still not sure how to make the msgbox wait to run until the user clicks save rather than as soon as they mark the box. Maybe applying it to the form instead of the checkbox itself?
 

IstyDawn

New member
Local time
Today, 04:25
Joined
Feb 25, 2020
Messages
7
See this related, older post by Pat Hartman for info.
Hope it's helpful.

Ok- I think I have it figured out and it seems to be working so far. I think I was over thinking it a bit. I had to go re-read that post (I may have only skimmed it the first time through) and one other.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Physician_Issue = True Then
If Nz(Me.Physician, False) = False Then
Cancel = True
MsgBox "Physician Field Required"
End If
End If
If Me.Coder_Issue = True Then
If Nz(Me.Coder, False) = False Then
Cancel = True
MsgBox "Coder Field Required"
End If
End If
If Me.Dept_Clinic_Issue = True Then
If Nz(Me.Dept_Clinic, False) = False Then
Cancel = True
MsgBox "Dept_Clinic Field Required"
End If
End If
End Sub
 

missinglinq

AWF VIP
Local time
Today, 05:25
Joined
Jun 20, 2003
Messages
6,423
IstyDawn said:
Maybe applying it to the form instead of the checkbox itself?

Yes...anytime one Control's appearance, Value, etc. depends on some state of another Control, you really need to do your checking/validation in the Form_BeforeUpdate event.

The reason is simple...You, as the developer, have no way to know in what order your end user will enter data! The Form's BeforeUpdate event is executed at the last second before the Record is saved, i.e. when the user is finished entering data.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom