Enable or Disable Checkbox with expression builder

K

Kaushik

Hi ,

Is that possible for me to enable or disable any control using iif
condition from the control source of a control in a access form?

Let me explain the problem. I have an Access form whose record source is a
SQL Query. The form have several Check boxes whose control source are
different fields from the query used in record source. This is very normal.
Now I have to enable or disable each check box depending upon a fild value
say "objnumber" which is also coming from the record source query. How can I
do that. I tried writing expresion in the control source property of each
check box with Expression Builder like -
iif(objnumber="16",chkCheckBox1.enabled="false",chkCheckBox1.enabled="true")
but that does not help more over I have to show the query field data also in
the checkbox.

Please help me
Thanks and Regards
Kaushik
 
K

Klatuu

I would use the form Current event to lock or unlock the controls. You also
have to consider how you want them for new records.

With Me
If .NewRecord Then
.CheckBox1.Enabled = True
.CheckBox2.Enabled = True
Else
.CheckBox1.Enabled = Some Condition
.CheckBox2.Enabled = Some Condition
End If
End With
 
J

Jeff Boyce

I'll assume you are trying to do this when the form "fills" with a record.
This is the "Current" event for the form.

In an event procedure for the form's "Current" event (i.e., "OnCurrent"),
you can add something like (untested):

Me!chkCheckBox1.Enabled = (Me!objnumber = 16)
Me!chkCheckBox2.Enabled = (Me!objnumber = 16)
...

(or ... = Not (Me!objnum...))

Or more elegantly, if you have several checkboxes to set, you could create a
variable in the event procedure and use that to do the setting, something
like (also untested):

Dim blnEnable as Boolean

blnEnable = (Me!objnumber = 16)

...

Me!chkCheckBox1.Enabled = blnEnable
...

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
K

Kaushik

Hi,

Klatuu,

It seems I couldnot make you understand my problem.Say I have 100
records that are coming from the record source query. So 100 check boxes are
generating. Each of these records have fields named "ObjNumber" and
"RCSub1". "RCSub1" is a boolean field and it's value gets reflected in
"RCCheck1" check box. As I have 100 records so 100 "RCCheck1" check boxes
will generate. Now I have to see each "ObjNumber" field and if the valeu of
any record in those 100 records is "16" then the corresponding CheckBox will
be disabled.

I tried your solution but current event not at all generating any new
record so at the time of opening the If loop is encountered and the control
flow is getting out.

Also the current event of the form is fired only once in time of opening,
how come I can check for "ObjNumber" field for 100 records there.

Please Let me know If You have any solutions

Thanks and Regards
Kaushik
 

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