Access Form

M

mikesmith20055002

I'm using Access 2000 to create a ballot (form) for an election. I
have the form all done. It has 4 images and a submit button. Under
each image is a checkbox. I want the user of the form to be able to
check mark (using the checkbox) the one image they choose and then to
hit the submit button (which closes the program).
The problem is that I don't know how to tell the form to allow only one
choice. How do I do this?
 
J

Jeff Boyce

One approach might be to use the form's BeforeUpdate event to validate that
only one is checked. This approach is less than desirable because it would
allow the user to check all before finding out that only one is allowed.

Another approach would be to create a procedure that adds all the checkboxes
(a "no" is zero, a "yes" is non-zero - a -1 in Access/Jet, a 1 in SQL
Server). Then, in each checkbox's AfterUpdate event, call the procedure and
see if the total absolute value is >1. If it is, more than one has been
checked, and you advise the user at that point.

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 
K

Klatuu

Any time you want to allow only one choice, the Option Group is the best
solution. In your case, it may be a little tricky because of the four
images, but if done correctly could actually be a better user interface. If
you create an option group and use option buttons, then put the images on the
buttons, the user could then select by clicking on the image rather than
having to find a check box.
 
M

mikesmith20055002

Thanks,
But how do I make sure after the user makes his choice that the choice
saves and the next user can make their choice.
 
K

Klatuu

If you want to be sure the user has made the choice he intended to make and
that his choice is saved, I would suggest you put code behind a command
button that will tell him which choice he has made and ask for confirmation.
Once the user confirms his choice, force an update. You can use the Caption
property of the selected toggle button to display his choice:
For example purposes
opgVote is the Option Group frame
tglVote1 - tghVote4 are the toggle buttons

Select Case Me.opgVote
Case 1
strMsg = "Frodo"
Case 2
strMsg = "Mickey Mouse"
Case 3
strMsg = "The Green Hornet"
Case 4
strMsg = "Rin Tin Tin"
End Select

If MsgBox("You Have Selected " & strMsg & vbNewLine & _
"Click Yes to Confirm or No to Correct Your Selection", _
vbQuestion + vbYesNo, "ConfirmVote") = vbYes Then
Me.Dirty = False
MsgBox "Thank You For Voting", vbExclamation + vbOkOnly, "Vote Registered"
End If
 
Top