Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Mar 2008
Location: Bristol, UK
Posts: 20
#1: Mar 12 '08
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

lee123's Avatar
Site Addict
 
Join Date: Feb 2007
Location: United States
Posts: 532
#2: Mar 12 '08

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


the code your looking for is this:

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

lee123
lee123's Avatar
Site Addict
 
Join Date: Feb 2007
Location: United States
Posts: 532
#3: Mar 12 '08

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


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.

lee123
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,000
#4: Mar 12 '08

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


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
  6.  
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


and

Me.Compressor.Value = True

mean the same thing.

Welcome to TheScripts!

Linq ;0)>
Newbie
 
Join Date: Mar 2008
Location: Bristol, UK
Posts: 20
#5: Mar 12 '08

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


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!
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,000
#6: Mar 12 '08

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


Two things:

Try

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


What version/service pack of Access are you using?

Linq ;0)>
Newbie
 
Join Date: Mar 2008
Location: Bristol, UK
Posts: 20
#7: Mar 12 '08

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


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!

Thanks
Newbie
 
Join Date: Mar 2008
Location: Bristol, UK
Posts: 20
#8: Mar 12 '08

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


By the way, Access 2003 SP3

Thank you
Reply