Is there a way to set all the text on a forms colour from VBA?

copleyuk

New member
Local time
Today, 15:31
Joined
May 28, 2010
Messages
1
Hi all,

I have a form which captures Environ("USERNAME") as String, what I want to be able to do is then be able to use the username value in an if statement to change the colour of all the text in the form.

So far I have:

Private Sub Form_Load()
Dim strUser As String
strUser = Environ("USERNAME")

If strUser = "A" Then me.??? = 123467

End Sub

I can enter specific object names after the me. to set the colour for that object but this will take a LONG time for all forms fields.

Thanks in advance.
 
Hi all,

I have a form which captures Environ("USERNAME") as String, what I want to be able to do is then be able to use the username value in an if statement to change the colour of all the text in the form.

So far I have:

Private Sub Form_Load()
Dim strUser As String
strUser = Environ("USERNAME")

If strUser = "A" Then me.??? = 123467

End Sub

I can enter specific object names after the me. to set the colour for that object but this will take a LONG time for all forms fields.

Thanks in advance.

Here is an example of how to loop through controls:

Code:
Private Function fCheckData() As Boolean
Dim ctl As Control
fCheckData = True
For Each ctl In Me.Controls
  If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then   'add any other valid control types here
     If ctl.Tag = "Req" Then
        If Nz(ctl.Name,"") = "" Then  'add your own validation or other checks here
           Msgbox "Please fill in required data",vbOKOnly + vbExclamation,"Required Data"
           ctl.Name.SetFocus
           fCheckData = False
           Exit For
        End If
     End If
  End If
Next ctl
End Function

The above code check for fields that are required.

This is not exactly what you want, but it show how to loop control, check type, and use the Tag property


I woudl recomned making a function to change teh coloer where you pas the color to it.

Code:
Private Sub Form_Load()
Dim strUser As String
strUser = Environ("USERNAME")
 
If strUser = "A" Then

    fSetColor 123467
Else

    fSetColor vbBlack

End If
 
End Sub

Where fSetColor would be the name of your function
 

Users who are viewing this thread

Back
Top Bottom