Highlight required controls (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Yesterday, 22:43
Joined
Jun 26, 2007
Messages
850
Hello, I want to highlight a control red if the tag says "Required" and I want to highlight the controls that the tag says "VerifyEmailorPrint". I can get that part BUT upon opening the form If there are controls that don't have data that is "Required" I want a message saying so and same goes for the "VerifyEmailorPrint". How would I go about this and what would I add to my function or the load/open event? Thanks!

I forgot to add, I cant get my option group to highlight. I tried adding 0 and nothing for its default and still wont highlight.

Code:
Public Function HighlightValidation()
Dim ctl As Control
For Each ctl In Me.Controls
    With ctl
        Select Case .ControlType
        Case acTextBox, acComboBox, acListBox, acCheckBox, acOptionGroup, acTextBox
            If .Tag = "Required" Then
            If IsNull(.Value) Or .Value = 0 Then
                    .BorderColor = vbRed
                    .BorderWidth = 3
                  End If
              End If
               If .Tag = "VerifyEmailorPrint" Then
               If IsNull(.Value) Or .Value = 0 Then
                    .BorderColor = vbYellow
                    .BorderWidth = 3
            End If
          End If
        Case Else
               'Return to origional colors
              .BorderColor = 14270637
              .BorderWidth = 0
        End Select
    End With
    Next ctl
End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:43
Joined
Aug 30, 2003
Messages
36,115
You can call your function from the current event, which fires when the form loads and when the user changes records.

I'll play with an option group when I get on a computer. Never tried to highlight one before.
 

oxicottin

Learning by pecking away....
Local time
Yesterday, 22:43
Joined
Jun 26, 2007
Messages
850
I tried using the below but it only fires the 'Do Nothing. Shouldn't ctl only bee looking for the correct .tag? I did a debug.print and it displayed info for every control in immediate window.

Code:
If Not IsNull(HighlightValidation) Or HighlightValidation = 0 Then
'Do nothing
Else
MsgBox "There are required fields that need filled!", vbInformation, "Fields are Needed"
End If
 

Isaac

Lifelong Learner
Local time
Yesterday, 19:43
Joined
Mar 14, 2017
Messages
8,710
Won't work on an option group unless your special effect property is FLAT.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:43
Joined
Feb 19, 2013
Messages
16,521
I can get that part BUT upon opening the form If there are controls that don't have data that is "Required" I want a message saying so
if your controls are textboxes you can use the format property to display 'Required' if it is null

for numbers the property might be

;;;[Red]"Required"

for text

@;[Red]"Required"

you can combine with conditional formatting if you want to change the back colour, use bold/italic etc
 

oxicottin

Learning by pecking away....
Local time
Yesterday, 22:43
Joined
Jun 26, 2007
Messages
850
Isaac, thanks that worked for getting the option group to outline!

Im still having trouble getting there to be a message when opening the form if a ctl .tag reads "Required" and is null or has no data give a message and if all "Required" tags have data don't give a message.
 

Isaac

Lifelong Learner
Local time
Yesterday, 19:43
Joined
Mar 14, 2017
Messages
8,710
Isaac, thanks that worked for getting the option group to outline!

Im still having trouble getting there to be a message when opening the form if a ctl .tag reads "Required" and is null or has no data give a message and if all "Required" tags have data don't give a message.
Ok, progress!

What happens if you change these bits:
If IsNull(.Value)

to:
If ("" & .Value) = ""
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:43
Joined
Aug 30, 2003
Messages
36,115
You have this test:

If Not IsNull(HighlightValidation) Or HighlightValidation = 0 Then

but the function does not return a value. At some point in the function you'd need:

HighlightValidation = Whatever
 

Users who are viewing this thread

Top Bottom