Multiple If Conditions

G

Guest

I'm a newbie to VB coding so any help is great! I have a form with six
checkboxes. I need some VB code where if the first five boxes are checked,
it will automatically check the sixth box.

I can get it to work where if a single box is checked, it will check the
master box with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([RMATask1]) = False Then

[RMAMasterCompleted] = "yes"

End If

End Sub

Also, how can you get the form to automatically refresh to show the sixth
box is checked?
 
G

Guest

Put the following in the Click event of each of your check boxes:
Me.Check10 = Me.Check0 + Me.Check2 + Me.Check4 + Me.Check6 + Me.Check8 = -5

Change the names to the names of your check boxes.
 
M

Marshall Barton

CCripe said:
I'm a newbie to VB coding so any help is great! I have a form with six
checkboxes. I need some VB code where if the first five boxes are checked,
it will automatically check the sixth box.

I can get it to work where if a single box is checked, it will check the
master box with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([RMATask1]) = False Then

[RMAMasterCompleted] = "yes"

End If

End Sub

Also, how can you get the form to automatically refresh to show the sixth
box is checked?


Note that the string "yes" is not the correct way to check a
check box. A check box should be set to either True (-1) or
False (0). Also, if the check box is bound to a Yes/No
field in a table, it can not be Null.

Without more details about these check boxes, I have to
assume that the check boxes are either unbound or bound to
an integer field in the table. In that case, I think this
will do what you want:

[RMAMasterCompleted] = (Nz(RMATask1,0) = True _
And Nz(RMATask2,0) = True And Nz(RMATask3,0) = True _
And Nz(RMATask4,0) = True And Nz(RMATask5,0) = True)
 
G

Guest

Klatuu, just for clarification, are you saying that for check1, for example
you would put a click event of:
Me.Check1 = Me.Check2 + Me.Check3 + Me.Check4 + Me.Check5 + Me.Check6 = -5

And then for check2, you would have a click event of:
Me.Check2 = Me.Check1 + Me.Check3 + Me.Check4 + Me.Check5 + Me.Check6 = -5


Klatuu said:
Put the following in the Click event of each of your check boxes:
Me.Check10 = Me.Check0 + Me.Check2 + Me.Check4 + Me.Check6 + Me.Check8 = -5

Change the names to the names of your check boxes.

CCripe said:
I'm a newbie to VB coding so any help is great! I have a form with six
checkboxes. I need some VB code where if the first five boxes are checked,
it will automatically check the sixth box.

I can get it to work where if a single box is checked, it will check the
master box with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([RMATask1]) = False Then

[RMAMasterCompleted] = "yes"

End If

End Sub

Also, how can you get the form to automatically refresh to show the sixth
box is checked?
 
G

Guest

Not based on your original post. Let's say the "Master Box" is check1.
you just need to add up the other 5 any time one of them is changed. Since
a checked check box has a value of -1, then if all 5 are checked, adding them
all up would return -5; therefore it would always be:
Me.Check1 = Me.Check2 + Me.Check3 + Me.Check4 + Me.Check5 + Me.Check6 = -5

You would not put that in Check1, because it is the Master you referred to.
If I msread your post, let me know and we will work out the correct solution.

CCripe said:
Klatuu, just for clarification, are you saying that for check1, for example
you would put a click event of:
Me.Check1 = Me.Check2 + Me.Check3 + Me.Check4 + Me.Check5 + Me.Check6 = -5

And then for check2, you would have a click event of:
Me.Check2 = Me.Check1 + Me.Check3 + Me.Check4 + Me.Check5 + Me.Check6 = -5


Klatuu said:
Put the following in the Click event of each of your check boxes:
Me.Check10 = Me.Check0 + Me.Check2 + Me.Check4 + Me.Check6 + Me.Check8 = -5

Change the names to the names of your check boxes.

CCripe said:
I'm a newbie to VB coding so any help is great! I have a form with six
checkboxes. I need some VB code where if the first five boxes are checked,
it will automatically check the sixth box.

I can get it to work where if a single box is checked, it will check the
master box with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([RMATask1]) = False Then

[RMAMasterCompleted] = "yes"

End If

End Sub

Also, how can you get the form to automatically refresh to show the sixth
box is checked?
 
G

Guest

Marshall, thanks so much. The code you gave me worked like a charm. Please
let me ask one more question....

You set this up so if the first five boxes are checked, the sixth "master"
box is checked. Is there a way where I can also have it so that checking the
sixth box will result in checking the first five?

Marshall Barton said:
CCripe said:
I'm a newbie to VB coding so any help is great! I have a form with six
checkboxes. I need some VB code where if the first five boxes are checked,
it will automatically check the sixth box.

I can get it to work where if a single box is checked, it will check the
master box with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([RMATask1]) = False Then

[RMAMasterCompleted] = "yes"

End If

End Sub

Also, how can you get the form to automatically refresh to show the sixth
box is checked?


Note that the string "yes" is not the correct way to check a
check box. A check box should be set to either True (-1) or
False (0). Also, if the check box is bound to a Yes/No
field in a table, it can not be Null.

Without more details about these check boxes, I have to
assume that the check boxes are either unbound or bound to
an integer field in the table. In that case, I think this
will do what you want:

[RMAMasterCompleted] = (Nz(RMATask1,0) = True _
And Nz(RMATask2,0) = True And Nz(RMATask3,0) = True _
And Nz(RMATask4,0) = True And Nz(RMATask5,0) = True)
 
G

Guest

Use the After Update event of Check6

If Me.Check6 = True Then
Me.Check1 = True
Me.Check2 = True
Me.Check3 = True
Me.Check4 = True
Me.Check5 = True
End If

If you want to also uncheck the other 5 when you uncheck 6:
Me.Check1 = Me.Check6
Me.Check2 = Me.Check6
Me.Check3 = Me.Check6
Me.Check4 = Me.Check6
Me.Check5 = Me.Check6

CCripe said:
Marshall, thanks so much. The code you gave me worked like a charm. Please
let me ask one more question....

You set this up so if the first five boxes are checked, the sixth "master"
box is checked. Is there a way where I can also have it so that checking the
sixth box will result in checking the first five?

Marshall Barton said:
CCripe said:
I'm a newbie to VB coding so any help is great! I have a form with six
checkboxes. I need some VB code where if the first five boxes are checked,
it will automatically check the sixth box.

I can get it to work where if a single box is checked, it will check the
master box with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([RMATask1]) = False Then

[RMAMasterCompleted] = "yes"

End If

End Sub

Also, how can you get the form to automatically refresh to show the sixth
box is checked?


Note that the string "yes" is not the correct way to check a
check box. A check box should be set to either True (-1) or
False (0). Also, if the check box is bound to a Yes/No
field in a table, it can not be Null.

Without more details about these check boxes, I have to
assume that the check boxes are either unbound or bound to
an integer field in the table. In that case, I think this
will do what you want:

[RMAMasterCompleted] = (Nz(RMATask1,0) = True _
And Nz(RMATask2,0) = True And Nz(RMATask3,0) = True _
And Nz(RMATask4,0) = True And Nz(RMATask5,0) = True)
 

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