Calculated Checkbox values

W

Wookawsh

Im trying to set a checkbox value to a "true" or "checked" state when another
field is equal to, or greater than another value in another field.
What would be the best way to do this?
(I guess I cant apply conditional formatting to checkboxes?)

Thanks for the help.
 
S

Steve

Put the following code in the Current event of your form:
If Me!NameOfFirstField = Me!NameOfSecondField Then
Me!NameOfCheckBox = True
Else
Me!NameOfCheckBox = False
End If

Steve
 
K

Klatuu

Conditional formatting doesn't have any effect on a control's value, only how
it looks. Here is a one liner that will do it:

Me.MyCheckBox = Me.SomeField <= Me.AnotherField
 
R

Ron2006

Also you will have to add that very same code to the after update
event of the two fields used in the logic.

If you do not do this then when you change either of them the checkbox
will NOT be changed until you get off of and return to the record.

Ron
 
W

Wookawsh

--
Lukasz


Ron2006 said:
Yes
Thank You for the prompt responses, its really impressive. I just need a little more help. My coding experience is limited.

First, I should have been more clear. This is the exact statment that I need
to execute

When Field 1 >= 12, then Checkbox 1 = Yes/Checked
(also will having this violate any database rules, as the checkbox value is
in one of my tables (i.e. is this like a calculated value?))

Ive found the "after update" in the code builder section, but I couldnt find
the "current event" field"

Once again your help and quick responses are appreciated. Thanks.
 
R

Ron2006

The OnCurrent event is an event for the form NOT a field.

It is the first one on the event tab on the properties for the form
itself.

Ron
 
W

Wookawsh

Thanks for that. If you wouldnt mind commenting on the other part of my
question. I tried to make it more specific as I dont think I was clear
enought before. Here is the expression Im trying to execute on my form:

When Field 1 >= 12, then Checkbox 1 = Yes/Checked
(also, will having this violate any database rules, as the checkbox value is
in one of my tables (i.e. is this like a calculated value?))

Thanks for all your help.
 
J

John Spencer

If Checkbox1 is always True when Field1 is greater than or equal to 12 and
always false otherwise, then this should be a calculated field. And you
should not store it in the table at all.

On a form or in a report you can add a checkbox control and set it's control
source to
= [Field1]>=12


In a query you can calculate the value with the same expression (minus the
first equals sign).


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

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