Conditional Format a Checkbox

JPW

Registered User.
Local time
Today, 22:54
Joined
Nov 4, 2007
Messages
51
Thanks to this forum I now use the below code in one of my forms in the database:

Private Sub TickRelease_AfterUpdate()

If Me.TickRelease = True Then
Me.LabelRelease.ForeColor = RGB(69, 139, 0)
Me.LabelRelease.Caption = "Release"
Else
Me.LabelRelease.ForeColor = RGB(238, 0, 0)
Me.LabelRelease.Caption = "No Release"
End If

End Sub

That code allows colour and text change of a label for a check box depending if it's checked or not, which is very useful for my users.

However, when it comes to my report I need something similar in a report. So when all the data is filled out in the form, and then I want to print of the coversheet/report I can have the tick box in the report but also the relevant changing text in the label depending on if the box is checked or not.
 
JP,

Reports are separate objects, so I'm afraid you are going to have to go through this process again for the report, just like you did for the form. Unfortunately, reports are not based off of forms; just source type objects, like tables and queries.

Try writing the same code you have above in a "Load" event (or maybe another one of your choice) of the report.
 
JP,

Reports are separate objects, so I'm afraid you are going to have to go through this process again for the report, just like you did for the form. Unfortunately, reports are not based off of forms; just source type objects, like tables and queries.

Try writing the same code you have above in a "Load" event (or maybe another one of your choice) of the report.


I'm trying to do the same thing basically. My question is, with that code, I need it to check the condition on each separate record that goes onto the report. For instance the first customer is Joe, and he is a VIP Customer, so I want to highlight his name and address, but the next customer is Sam and he isnt, so I dont want his name and address highlighted.

How can I do that?

Example control names:

Me.Name
Me.Address
Me.VIP


If Me.VIP = "Yes" then
Me.Name.Backgroundcolor = "grey"
Me.Address.Backgroundcolor = "grey"
Else
Me.Name.Backgroundcolor = "white"
Me.Address.Backgroundcolor = "white"
End If


Now I know that "backgroundcolor" is not the right property, so I need that too lol. I am not a coder. Can you help me with my code to make mine work?
 
Leopard,

The best way to do this outside of Visual Basic is to use the conditional formatting wizard. Open your report, right click on the field control, not the label, and the wizard should be there in the list. I believe this is available for Access 2000 and above...

This gives you basic options, and should compliment your needs.

Also, the properties that you would want in VB are .BackColor and .ForeColor ;)
 
I dont geta wizard, I get the conditional formatting window. OK, so I chose Expression is, and it gives me a line to enter an expression to match.

I tried:

Me.Designated = "True"


That did nto work. The Designated is the name of the control, and it is a checkbox control. When I opened my report, it popped up a window asking me to define Me.
 
Leopard,

I thought you were trying to format a control based on its own condition. Sorry.

Also, the conditional window is not a wizard, you're right, it is just a window.

Anyway, to format a control's (record's) value in a report based on a checkbox being true, you will have to use VB...
Code:
If Me.CheckBoxName = True (or you can use "-1" here) Then
   Me.ControlYouWantToFormat.PropertyOfChoice = YourSpecificationHere
End if
Also, I would rename your field called "Name". That's a reserved word. Danger, Danger... ;)
 
Now with that code, will it oly do it if that particular customer matches, I mean does it run it for every record and only match those that match?

Also, where do I enter the code at?
 
Now with that code, will it oly do it if that particular customer matches, I mean does it run it for every record and only match those that match?

Also, where do I enter the code at?
Yes, if you're report is, indeed based on a recordset of some sort, then you should have, in design view, controls that are actually representations of fields, and controls that are the corresponding labels for the fields. When you set a condition based on the control that represents a field, that condition is applied to every record in that field, thus corresponding to that control on the report.

When I do something like this, I usually LOAD the report this way. That is, in design view, get into the properties box, and write the code for the "OnLoad" event of the report itself.
 
Hello all. Not read this thread for a few days, but I do need a soloution to my problem if possible.

I have the report constructed and entered the following code into the VB code builder:
Option Compare Database

If Me.TickRelease = True Then
Me.LabelRelease.caption = "Vehicle Can Be Released"
Else
Me.LabelRelease.caption = "Vehicle Can't Be Released"

End If

I'm obviously have a forum in which the check box is either selected as true or not true, but I do need in a label box or a text box for some text to be displayed as seen in the code.

However, above that code that I have in the Report VB module it does say at the top "Option Compare Database", so all in all I'm very confused.

I've also tried this code in the OnLoad section of the report and get a error message saying something like "Database Name can't find object If.Me"
 

Users who are viewing this thread

Back
Top Bottom