Set checkbox Yes/No based on other checkboxs' states

S

straits58

First the disclaimer: I am a newbie to Access Monster, Access, and
Programming who is trying to teach himself enough to be dangerous. I've tried
for a week to search Access Monster before resorting to a Post that is
certainly a complete "Duh!" for anyone with a modicum of Access and/or
Programming knowledge.
OK, now with that off my chest...

I'm working with a shared database of which I am not the 'owner', however I
update certain record's and generate reports that depend on the updates. I've
got a Query that pulls from two tables (I'll call them A & B). I've created a
Form using that Query as its Record Source. On the Form I have three
checkboxes from Table A (I'll call them 1,2,3), and one checkbox from Table B
(I'll call it 4). I am trying to update checkbox 4 based on the 'state' of
checkboxes 1,2,3.

Here are the conditions I'm trying to enforce for checkbox 4:
If 1 or 2 or 3 is checked, then 4 is checked
If 1 and 2 and 3 are unchecked, then 4 is unchecked

My feeble attempt at figuring out the code is:
If Me.1 = True Or Me.2 = True Or Me.3 = True Then
Me.4 = True
Else
Me.4 = False
End If

First of all, is the code close to workable? Then, whatever the code needs to
be, I don't have a clue as to where to 'insert' it into my form. I assume it
has to be at what I would call the 'global' level of the form rather than
attached to a specific control on the form, but I basically don't have a clue.


Any help would be appreciated beyond words.

Steve
 
M

Marshall Barton

straits58 said:
First the disclaimer: I am a newbie to Access Monster, Access, and
Programming who is trying to teach himself enough to be dangerous. I've tried
for a week to search Access Monster before resorting to a Post that is
certainly a complete "Duh!" for anyone with a modicum of Access and/or
Programming knowledge.
OK, now with that off my chest...

I'm working with a shared database of which I am not the 'owner', however I
update certain record's and generate reports that depend on the updates. I've
got a Query that pulls from two tables (I'll call them A & B). I've created a
Form using that Query as its Record Source. On the Form I have three
checkboxes from Table A (I'll call them 1,2,3), and one checkbox from Table B
(I'll call it 4). I am trying to update checkbox 4 based on the 'state' of
checkboxes 1,2,3.

Here are the conditions I'm trying to enforce for checkbox 4:
If 1 or 2 or 3 is checked, then 4 is checked
If 1 and 2 and 3 are unchecked, then 4 is unchecked

My feeble attempt at figuring out the code is:
If Me.1 = True Or Me.2 = True Or Me.3 = True Then
Me.4 = True
Else
Me.4 = False
End If

First of all, is the code close to workable? Then, whatever the code needs to
be, I don't have a clue as to where to 'insert' it into my form. I assume it
has to be at what I would call the 'global' level of the form rather than
attached to a specific control on the form, but I basically don't have a clue.


If you want 4 checked when at least one of 1,2,3 are
checked, then you can use:

Me.4 = Me.1 Or Me.2 Or Me.3

The line of code would go in the AfterUpdate events of check
boxes 1, 2 and 3. You can get to the event procedures by
double clicking on one of the check boxes to display its
property sheet. Select the Events tab at the top of the
property sheet and scan down the list for After Update.
Select Event Procedure in the down list on the right. Then
click the code builder button with three dots. That will
display the form's module and place the cursor on the line
where you should put the line of code.

Use Copy (Ctrl+C) to copy the line of code you just entered
and repeat the above to Paste the line into the other two
check boxes event procedure.
 

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