Update Label Caption Based on Multiple Checkbox values

LarryB

Registered User.
Local time
Today, 10:09
Joined
Jun 19, 2012
Messages
66
Hi all,

As simple as this seems, this is giving me the run around!:banghead:

I have 3 check boxes in a table and form associated. Based on the values of these checkboxes, and different combinations, other controls become active or inactive. This is working fine for me in the form on current section of my code.

I decided to update a label on the form based on the values of the checkboxes. But it seems to only work for the first record in my form.

I have even tried to put the code behind a command button and I have separated the If statements but it only seems to apply to the first record of the form, and not when I scroll to the next record which has different checkbox values

Checkbox names

editing
check
closed_fund

Label name

status

code

If Editing.Value And Closed_Fund.Value = True Then
Status.Caption = "Pending Approval - Fund Closue"
Else
If Closed_Fund.Value And Check.Value = False Then
Status.Caption = "Editing In Progress"
Else
If Editing.Value And Check.Value = True Then
Status.Caption = "Pending Approval"
End If
End If
End If

In my case, the first record in my table has both editing and check values as true and the correct label caption is showing.

Any advice

Cheers

LarryB
 
You need to use the form's ON CURRENT event to do this but it will only work in Single form view and not datasheet or continuous view.
 
Hi Bob,

Many thanks for your reply.

The code itself is already in the On Current section of the forms code and the default view is Single Form and not continuos

I changed the Datasheet view to No, bit unfortunately the code still does not work.

I have just tried referring to the fields in question using the context [forms]![form_name]!field_name.property, but this has also failed.

I'll create a new db with forms and have a play around with this. The code is basic and it should work!

Any other suggestions will be much appreciated

Regards

Larry
 
one issue might be to do with the check boxes you are testing. if the values are null, rather than true or false, the code may not work correctly.

you could use

if nz(somecheckbox, false) = false etc to pick this up.

alternatively, i would add a breakpoint and step through the code with F8 to see what is really going on, with one of the values that doesn't seem to work correctly.
 
Hey Gemma, thanks for the input!

After stepping through the code from what I could see it wasn't recognizing the first checkbox of the AND statement as True

After amending the code to

If me.Editing = true And me.Closed_Fund = True Then
Status.Caption = "Pending Approval - Fund Closue"
Else
If me.Closed_Fund = False And Check.Value = False Then
Status.Caption = "Editing In Progress"
Else
If me.Editing = True And Check.Value = True Then
Status.Caption = "Pending Approval"
End If
End If
End If

Simple If statements checking the value of only one checkbox works fine too.

I don't make it easy on myself :mad:

Anyways, project complete. One more demo for the end user, then this one is off my desk!

Lovely hurlin!

Thanks again

Larry
 
it's possibly the value argument

if you have a boolean checkbox then just using the control name without specifically testing for true/false should work

so

if checkbox1 and checkbox2

or

if not checkbox1 and not checkbox2

are valid statements
 

Users who are viewing this thread

Back
Top Bottom