Changing Colors On Click

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
 
D

Dan Artuso

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
 
P

PC Datasheet

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!
 
D

Dave Cousineau

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
 
P

PC Datasheet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top