Change Form Background Color

J

Jen

I am trying to change the background color of the form or the detail section
when a value of DoNotCall = yes. I have tried several things and none are
working. The field is a Yes/No field and the name is DoNotCall. When a
record has this field set to true (is checked) then the background color
should turn to red. Here is what I tried and I can't get it to work.

Private Sub Form_Current()
If Me.DoNotCall = "Yes" Then
Me.Form.BackColor = 255
End If
End Sub

Private Sub Form_Load()
If Me.DoNotCall = "Yes" Then
Me.Detail.BackColor = vbRed
End If

End Sub

Any help would be appreciated!
 
D

Daniel Pineault

How about something more like:

Private Sub Form_Current()
If Me.DoNotCall = True Then
Me.Section("Detail").BackColor = 255
Else
Me.Section("Detail").BackColor = -2147483633
End If
End Sub
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
F

fredg

I am trying to change the background color of the form or the detail section
when a value of DoNotCall = yes. I have tried several things and none are
working. The field is a Yes/No field and the name is DoNotCall. When a
record has this field set to true (is checked) then the background color
should turn to red. Here is what I tried and I can't get it to work.

Private Sub Form_Current()
If Me.DoNotCall = "Yes" Then
Me.Form.BackColor = 255
End If
End Sub

Private Sub Form_Load()
If Me.DoNotCall = "Yes" Then
Me.Detail.BackColor = vbRed
End If

End Sub

Any help would be appreciated!

1) The value of a Yes/No check box is -1 or 0.
You could substitute the constants True or False (Note: there are no
quotes around the constants as they are number values, not text
values.)
The constants Yes and No (again no quotes) are not VBA constants.
If you're ever unsure of where to use what, just use the actual number
value, -1 or 0:
If Me.DoNotCall = -1 Then

2) If you change the color to something it will stay that color unless
you have code restoring the color back to the original.
You need an If .. Then .. Else code.

3) Also, the Load event is not the correct event to use. it only fires
the when the form is loaded first loaded.
Use the Form's Current event, and also place the same code in the
Check Box control's AfterUpdate event.

Private Sub Form_Current()
If Me.DoNotCall = True Then
Me.Detail.BackColor = vbRed
Else
Me.Detail.BackColor = vbBlue
End If

End Sub

Change vbBlue to whatever actual color value you wish.
 

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