Highlight required controls (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Today, 03:31
Joined
Jun 26, 2007
Messages
666
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
Today, 00:31
Joined
Aug 30, 2003
Messages
34,811
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
Today, 03:31
Joined
Jun 26, 2007
Messages
666
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
Today, 00:31
Joined
Mar 14, 2017
Messages
3,199
Won't work on an option group unless your special effect property is FLAT.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 08:31
Joined
Feb 19, 2013
Messages
12,755
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
Today, 03:31
Joined
Jun 26, 2007
Messages
666
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
Today, 00:31
Joined
Mar 14, 2017
Messages
3,199
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
Today, 00:31
Joined
Aug 30, 2003
Messages
34,811
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