Checkbox Click (and Afterupdate?)

G

Guest

I have a form with multiple checkboxes in the following format:
_X_ Northeast
_X_ New England _X_ State1 _X_ State2 ...
_X_ Mid Atlantic _X_ State5 _X_ State6 ...

Using the following code in the On Click Event I was able to select all the
states in each row (i.e. all the states in New England):
If (Me."New England") Then
Me.State1 = True
Me.State2 = True
...
Else
Me.State1 = False
Me.State2 = False
...
End If

I thought that if I were to apply the same principle to the "Northeast"
checkbox...:
If (Me."Northeast") Then
Me."New England" = True
Me."Mid Atlantic" = True
Else
Me."New England" = False
Me."Mid Atlantic" = False
End If

....clicking the "Northeast" would select the "New England" and "Mid
Atlantic" boxes, (which would in turn select all the states). However,
clicking the "Northeast" checkbox only selects the "New England" and "Mid
Atlantic" boxes, NOT any of the states.

What code am I missing? An Afterupdate event? And would it be placed: in
the "Northeast" checkbox, "New England" checkbox, or in each state's checkbox?
 
G

Guest

First, you should not be putting quotes around control names
If (Me."Northeast") Then Should be
If (Me.Northeast) Then

Then, you are specifying regions, not states.
You can't cascade the controls like that, you have to do them all by hand.
 
G

Guest

Thanks for getting back to me. I only had the quotation marks around the
control names because I was calling them something else and was trying to
make my question easier to follow...

I thought it was possible to call Subs in an AfterUpdate? If, in my example
below, the event New_England_Click() selects all the states' checkboxes, and
the event Northeast_Click() checks the New_England checkbox, putting an
afterupdate on the Northeast checkbox something very roughly along the lines
of...:

Private Sub Northeast_AfterUpate()
Sub New_England_Click()
End Sub

....so the code in effect is 'saying':
"OK, Northeast checkbox = True = New_England checkbox, now go back and run
the Sub for New_England_Click(). If New_England checkbox = True, then State1
= True, State2 = True, etc...."

Thanks again for your help.
 
G

Guest

You can call subs and function from anywhere as long as they are within
scope. If they are not, you will get an error.
Sorry, but the quotes do not clarify, they confuse. If you can post the
exact code, perhaps we can help.
 
G

Guest

Dave, I replied this morning but the post isn't there, let's try again....

Code in the Mid Atlantic Region checkbox called REG_NE_MA OnClick event to
check the checkboxes State_NJ, State_NY, & State_PA when the REG_NE_MA is
clicked:

Private Sub REG_NE_MA_Click()
If (Me.REG_NE_MA) Then
Me.State_NJ = True
Me.State_NY = True
Me.State_PA = True
Else
Me.State_NJ = False
Me.State_NY = False
Me.State_PA = False
End If
End Sub

--(The code for the other part of the region's checkbox, REG_NE_NE , looks
just like that...)

Here is code in the Northeast Region checkbox called REG_NE OnClick event to
check the REG_NE_MA and REG_NE_NE checkboxes when the REG_NE checkbox is
checked:

Private Sub REG_NE_Click()
If (Me.REG_NE) Then
Me.REG_NE_MA = True
Me.REG_NE_NE = True
Else
Me.REG_NE_MA = False
Me.REG_NE_NE = False
End If
End Sub

I think the solution to my problem is to be able to put code in the
AfterUpdate Event of REG_NE to run the subs REG_NE_MA_Click() and
REG_NE_NE_Click() ...

I've been looking at these Access help forums but haven't been able to find
anything like what I'm trying to do in the AfterUpdate Event...

Thanks so much for your help,
Kevin
 
G

Guest

REG_NE_MA_Click() looks like it should work just fine. the parenthises
aren't necessary, but should not change anything. May I show you a way that
will save you a few lines of code?

Private Sub REG_NE_MA_Click()
Me.State_NJ = Me.REG_NE_MA
Me.State_NY = Me.REG_NE_MA
Me.State_PA = Me.REG_NE_MA
End Sub

So if Me.REG_NE_MA is True (Checked) so will the states.

Th other thing I would sugges would be to put breakpoints in the code were
you think it is not executing and see what happens.
 
G

Guest

Thanks for your help. I'm back on this project and have figured out a
solution to the problem. Instead of an AfterUpdate event, the code that I
didn't have was to simply "Call" the subs. Now clicking on the Northeast
Region checkbox checks the two sub-regions AND all the underlying states.

Private Sub REG_NE_Click()
Me.REG_NE_MA = Me.REG_NE
Me.REG_NE_NE = Me.REG_NE
Call REG_NE_MA_Click
Call REG_NE_NE_Click
End Sub

BTW- you weren't kidding about cleaning up that code, it looks a lot better
the way you mentioned. Thanks!
 
G

Guest

Glad I could help.

The brevity of the code is because I am lazy. I have determined that lazy
people are the ones who are responsible for innovation. Hard working people
will plug along diligently doing good work. Lazy people, however, will try
very hard to get out of doing work, but still get the task accomplished. :)
 

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