Changing Colors On Click

  • Thread starter Thread starter David Ehrenreich
  • Start date Start date
D

David Ehrenreich

Hello All,

I would like to add to this click event. When the user
clicks on the social security it will change the back
color of three other feilds(fname,Lname,Date) in the form.

Private Sub Social_Click()
Me.Parent.TempSSN = Me.ssn
End Sub
 
Hi,
Try this:

Private Sub Social_Click()
Me.Parent.TempSSN = Me.ssn
Me.fname.BackColor = 10485760
'repeat for other controls
End Sub

You'll have to make the changes in design view first in order to get the
correct color numbers
 
Open your form in design view. Select one of the controls and open properties.
Change the backcolor to the color you want. Note the backcolor property number,
for example, red is 255. Change it back to the original color.

In your code add:

Me!FName.Backcolor = "255"
Me!LName.Backcolor = "255"
Me!Date.Backcolor = "255"

Note - they don't all have to be the same color.

BTW - naming a field Date is bad practice. Date is a reserved word. You will run
into problems with this!
 
i would also suggest defining some constants instead of
using hardcoded values:

ie:

Global Const RED = "255"
etc...

MyControl.BackColor = RED

a. its a lot easier to read
b. RED is much easier to remember than "255", and other
colors are not as simple as 255

anyway just my opinions
 
Dave,

Good suggestion! If you are using a standard color like Red, you can use the
built-in constant for the color:

MyControl.BackColor = VbRed
 
Back
Top