Format a background color from VBA?

M

marko

Hi!
I ahve a form with a record source, it is a continuos form.
How can i say to access that i want to format my field which name is
"Date" when a user presses a toogle button?
I tried:

If toogle7=true then Date.BackColor=42790

but it wont work.
Do i have to say something like docmd.GotoControl.... before?
Please help! I'm pretty new at VBA!
Thanks

Marko
 
A

Allen Browne

You have a field named Date? That's a reserved word in VBA for the system
date, and I'm sure that VBA will think that the system date does not have a
back color.

To make the change, ensure the Name AutoCorrect boxes are unchecked under:
Tools | Options | General
Then compact the database:
Tools | Database Utilities
Then open the table in design view, and change the field name to InvoiceDate
or something. Then change the name in any queries, forms, and reports as
well. Then compact again.

Now we come to the color change. In the AfterUpdate event of your toggle
button:
If (Me.Toggle7.Value) Then
Me.[InvoiceDate].BackColor = 42790
Else
Me.[InvoiceDate].BackColor = vbBlack
End If

Note that this code will make the entire column green, not just the current
row of your continuous form.
 
M

marko

Thanks! And how can I back.color just some fields, let's say those
whose date is greater then 01.01.2004.?
Thanks

Marko
 
A

Allen Browne

If this is Access 2000 or later, use conditional formatting (Format menu.)
No code is needed.
 
M

marko

Yes, i am aware of the conditional formatting but i want the user to be
able to swich on or off the highlight with a toogle buttont! Can you
please help me?
Thanks for all your help so far!
Best regards,

Marko
 
A

Allen Browne

From the code window, look up help on:
FormatConditions Collection

You can modify the BackColor of the FormatCondition to turn in or or off.
 
Top