Highlight mandatory controls on a form tab

thebionicredneck

Registered User.
Local time
Today, 18:02
Joined
May 9, 2013
Messages
16
Hi everyone,

I am trying to provide a visual highlight for users of a multi tabbed form. I do a check as users go from tab and tab and i.e. on exit event and I would like to highlight all mandatory fields that have been left incomplete.

I did a test with one control and it worked as expected with the after update event of the specific control.

I then altered the code to add another control, but it does not work as expected. It only highlights one control and not the other. I just recently started using vba, so I am open to suggestions so I can adapt the code to fit multiple controls and make it work as expected.

Private Sub Ctl2_frm_tab1_Exit(Cancel As Integer)

If (Len(Form_2.cmb_arName& "") = 0 Or IsNull(Form_2.cmb_arName)) Or _
(Len(Form_2.cmb_val & "") = 0 Or IsNull(Form_2.cmb_val)) Then
Cancel = True
MsgBox "Please complete the highlighted control", vbCritical + vbOKOnly
Form_2.cmb_arName.SetFocus
Form_2.cmb_arName.BorderColor = RGB(255, 0, 0)
Form_2.cmb_val.BorderColor = RGB(255, 0, 0)

ElseIf Len(Form_2.cmb_arName& "") > 0 Or Not IsNull(Form_2.cmb_arName) Or _
Len(Form_2.cmb_val & "") > 0 Or Not IsNull(Form_2.cmb_val) Then
Form_2.cmb_arName.BorderColor = RGB(255, 255, 255)
Form_2.cmb_val.BorderColor = RGB(255, 255, 255)

End If

Exit Sub

End Sub


Many thanks
 
I typically use Conditional Formatting to highlight controls that still need to be filled out. To do it your way, you want a stand alone test for each rather than ElseIf.
 
Can you please give me an example of how to use conditional formatting in a form?

Thanks
 
Play with it and post back if you get stuck. I'm just on an iPad right now.
 

Users who are viewing this thread

Back
Top Bottom