By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,333 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,333 IT Pros & Developers. It's quick & easy.

If Checkbox 1 - True How do I make Check 2 = True

P: 22
Two check boxes on the same form. I need to make check box 2 = TRUE if Check one is clicked (and so made TRUE)

The following code does not work

Private Sub AirSparging_AfterUpdate()
If Me.AirSparging = True Then Me.Compressor = True
Else: Me.Compressor = False

End Sub

Clearly I am getting something wrong. Can anyone help?

Thank you
Mar 12 '08 #1
Share this Question
Share on Google+
7 Replies

P: 556
the code your looking for is this:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub AirSparging_AfterUpdate()
  3. If  AirSparging.value = True Then 
  4.         Compressor.value = True
  5. Else:
  6.        Compressor.value = False
  7. End If
  9. End Sub
you could try this, when you are dealing with these checkboxes you need to put the value of it in the code.

Mar 12 '08 #2

P: 556
oops i forgot the code brackets who which ever moderator see this i can't seem to be patient enought to get that, i know it easy to do but my hands are faster than my mind and eyes. sorry for that but if i could change it i would but i don't know how to and probably can't.

Mar 12 '08 #3

Expert 2.5K+
P: 3,532
Hulm1, Your code was almost correct. This line

If Me.AirSparging = True Then Me.Compressor = True

by itself would be correct. You can place an If...Then statement on a single line, and if you do you don't need an End If statement to match. But when you have an If...Then statement on a single line, you cannot have an Else statement as well. To add the Else statement you have to use the standard If...Then construct along with the End If statement. So your code then becomes

Expand|Select|Wrap|Line Numbers
  1. If Me.AirSparging = True Then
  2.   Me.Compressor = True
  3. Else
  4.   Me.Compressor = False
  5. End If
which is the same as lee123's code, because his statement

when you are dealing with these checkboxes you need to put the value of it in the code.

is incorrect. Since .Value is the default property of Checkboxes, comboboxes and textboxes,

Me.Compressor = True


Me.Compressor.Value = True

mean the same thing.

Welcome to TheScripts!

Linq ;0)>
Mar 12 '08 #4

P: 22
Thank you very much indeed both who replied. However!

If Me.AirSparging = True Then Me.Compressor = True

Does not actually work for some reason. It is actually what I did first.

I wonder if it could be due to either of the following:

Either: because there are two other check boxes that would also
make "compressor" True

If Me.TotalFluidsPumps = True Then Me.Compressor = True
If Me.LNAPLSkimmers = True Then Me.Compressor = True

OR: Because the AfterUpdate event for these checkboxes is not the correct place?

Your help greatly appreciate!
Mar 12 '08 #5

Expert 2.5K+
P: 3,532
Two things:


If Me.AirSparging = -1 Then Me.Compressor = -1

What version/service pack of Access are you using?

Linq ;0)>
Mar 12 '08 #6

P: 22
Thank you again.

While going back into the code to change to "-1" as you suggested, I discovered that while the code was in their, the Properties for "AirSparging" did not show an AfterUpdate Event even though the code was actually in the VBA Editor. I therefore selected AfterUpdate event which took me to the code. I then closed the VBA editor and hey presto! it works. I have encountered that one before so I should have spotted it.

One thing though.

You may recall that I have three separate check boxes which control whether or not Compressor = true (4 if you include the Compressor Check box). It sounds strange but the reason this is needed is that we may provide a quote for just a compressor, or we may provide a quote for air sparging (or total fluids pumps etc.) for which a compressor is needed anyway.

If NONE of the check boxes are True then I need Compressor to be False. If any ONE is True I need compressor to remain TRUE. (For reference, I have a subform "EnquiryCompressor_Edit" which is visible (or not) based on the above check boxes as well. So I have the same issue relating to that.)

For reference, I am using the following code to make the subform(s) visible

Me![EnquirySparging_Edit].Form.Visible = Me.AirSparging
Me![EnquiryCompressor_Edit].Form.Visible = Me.AirSparging

Can you help with this? I feel like I am making off with the jewelery here if I get all this help!

Mar 12 '08 #7

P: 22
By the way, Access 2003 SP3

Thank you
Mar 12 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.