Professional Documents
Culture Documents
Database - Voting System Using Microsoft Access - Stack Overflow
Database - Voting System Using Microsoft Access - Stack Overflow
Asked 6 years, 3 months ago Modified 6 years, 3 months ago Viewed 2k times
1) I don't know how to "Add 1" to the field 2) I can't find a way to avoid the user from selecting
more than one candidate (Using checkboxes)
If (Me.Check1 = True & Me.Check2 = True & Me.Check3 = True & Me.Check4 = True) Then
MsgBox "You can't select them all, you can only choose one"
DoCmd.Close
DoCmd.OpenForm "Ir a"
End If
database ms-access
Report this ad
Your If statements are problematic. You are not properly building your logical statements. &
concatenates two strings together. AND is a logical operator that links two conditions to the
Checkboxes have a unique characteristic that lets IF Me.Check1 = True Then mean the same
thing as If Me.Check1 Then . That's because the reference Me.Check1 will evaluate to either a
True or a False, exactly the parameter expected by the If statement.
The problem is, you cannot just use & to logically compare multiple tests. Your first If
statement should read:
IF(Me.Check1 = True AND Me.Check2 = True AND Me.Check3 = True) Then or the simpler
If(Me.Check1 AND Me.Check2 AND Me.Check3) Then where the evaluation of each reference will
result in either True or False and the AND operator combines them together to evaluate the entire
statement to a True or False.
Now that should work.
But I have to ask, do you really want to wait until the button is pressed to give feedback to the
user? It's even simpler to build a toggling routine on the checkboxes:
If Me.Check1 Then
Me.Check2 = False
Me.Check3 = False
Me.Check4 = False
End If
Now adjust that code for each of the other three checkboxes, first checking whether that
checkbox is true, and if so, all others must be false.
This approach resets all checkboxes any time the user checks any checkbox. That way, you don't
need to validate their selections during submission, making your code much easier to manage.
As for updating the vote tally, you will need two pieces of information and a sql UPDATE
statement. The two pieces of info you need are: a unique way to identify which row in your table
needs another vote and the current vote tally for that candidate/row. Do you know how to get
that information? Do you know how to create and run an Update statement that will work
regardless of who is being voted for? Hint: I would suggest using either a recordset or a query
definition object, please take a stab at updating a record using one of those two methods, there
should be tons of resources for both online.
Although, my update statement doesn't work (It says sub doesn't exist): This is what I have If Me.Check1 =
True Then Update Candidatos Set Votos = Votos + 1 WHERE [Nombre] = Marco End If – Shredder Oct 24,
2017 at 14:31
Your update is invalid and is not being called correctly. What is "Macro"? And you cannot use Votos = Votos
+ 1. Try researching how to execute an update sql statement with vba. – MoondogsMaDawg Oct 24, 2017
at 16:09