Hello I just have a couple of questions about checkboxes.
I'm currently putting in a kind of multiple choice quiz into a document. I have some questions with the check boxes bellow them and at the end a button to press to submit it and one to reset it.
I used the follow VBA on the submit button where the Correct answer was the 2nd choice:
If checkbox2.Value = True Then
answer1.Caption = "Correct"
Else
answer1.Caption = "Incorrect"
End If
Now if the correct box is checked then it says "Correct" and if any of the incorrect boxess are checked then it says "Incorrect" like it should, however, if both the correct and an incorrect box are checked it still comes up "Correct". I only want it to say "Correct" if only the correct answer is chosen and nothing else.
I have got around the problem with the following code:
If checkbox2.Value = True Then
answer1.Caption = "Correct"
Else
answer1.Caption = "Incorrect"
End If
If checkbox1.Value = True Then
answer1.Caption = "Incorrect"
End If
If checkbox3.Value = True Then
answer1.Caption = "Incorrect"
End If
If checkbox4.Value = True Then
answer1.Caption = "Incorrect"
End If
That works fine so if the wrong box or any other boxes are checked along with the correct box it will display "Incorrect" but is quite cumbersome (and will be quite time consuming to do it over multiple documents with lots of questions) so is there a way to add a kind of clause to the statement so it does something like:
If checkbox2 = True AND checkboxes 1,3,4 = False Then
answer1.Caption - "Correct"
Else
answer1.Caption = "Incorrect"
End If
Secondly I have some questions where you have to select two or three of the answers, so if in the example above the answers were boxes 2 and 4, how would I make it display "Correct" only when both boxes are checked and "Incorrect" if one of the incorrect are checked or there is only one box checked?
The best I can come up with is this, where it works fine if both correct answers are chosen, no correct answers are chosen or only checkbox2 is chosen (as in it displays "Incorrect" because both answers arn't chosen), but if I have checkbox4 chosen and any incorrect answer or no other answer, it displays "Correct" instead of "Incorrect".
If checkbox2.Value = True Then
answer1.Caption = "Correct"
End If
If checkbox4.Value = True Then
answer1.Caption = "Correct"
Else
a8.Caption = "Incorrect"
End If
If checkbox1.Value = True Then
answer1.Caption = "Incorrect"
End If
If checkbox3.Value = True Then
answer1.Caption = "Incorrect"
End If
And lastly I can't seem to find anything with google for doing something as simple as making the "submit" button also go to the top of the document when it is clicked.
Resolution: use an "And" statement within the IF e.g.
Code:
If q1c.Value = True And q1a = False And q1b = False Then
a1.Caption = "Correct"
Else
a1.Caption = "Incorrect"
End If
I tried that before and it wouldn't accept the "And" but now it is accepting it no problem.