<%
'Dimension variables
Dim adoCon 'Database Connection Variable
Dim rsWeeklyPoll 'Database Recordset Variable to hold the eweekly poll recordset
Dim strAccessDB 'Holds the Access Database Name
Dim strSQL 'Database query sring
Dim strPollQuestion 'Holds the poll question
Dim intPollIDNum 'Holds the Poll ID Num
Dim intSelectionLoopCounter 'Loop counter to display the poll selections
Dim intVotedIDNo 'Holds the ID Number the last vote the user voted in if there is one
Dim blnCheckForPoll 'Set to false if there are no weekly polls in the database
Dim blnAlreadyVoted 'Set to true if the user has voted in this weeks poll
'Error Trapping
On Error Resume Next
'Intilaise variables
blnCheckForPoll = True
blnAlreadyVoted = False
intPollIDNum = 1
'Initialise the strAccessDB variable with the name of the Access Database
strAccessDB = "weekly_poll.mdb"
'Create a connection odject to the database
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsWeeklyPoll = Server.CreateObject("ADODB.Recordset")
'Open connection to the database driver
adoCon="DRIVER={Microsoft Access Driver (*.mdb)};"
'Open Connection to database
adoCon = adoCon & "DBQ=" & server.mappath(strAccessDB)
'Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM tblPolls ORDER By id_no DESC;"
'Query the database
rsWeeklyPoll.Open strSQL, adoCon, 3
'Check there is a weekly poll to display
If rsWeeklyPoll.EOF Then
'If there is no weekly poll in the database chenge the blnCheckForPoll variable to false
blnCheckForPoll = False
Else
'Read in the polling question from the database
strPollQuestion = rsWeeklyPoll("Question")
'Read in the Weekly Poll ID number
intPollIDNum = CInt(rsWeeklyPoll("id_no"))
'Loop round to read in the number of votes cast
For intReadInVotesLoopCounter = 1 To 7
'Read in the total number of votes cast
intToatalPollVotes = intToatalPollVotes + CInt(rsWeeklyPoll("Votes_" & intReadInVotesLoopCounter & ""))
Next
'Check the user has not already voted by reading in a cookie from there system
'Read in the Poll ID number of the last poll the user has voted in
intVotedIDNo = CInt(Request.Cookies("Poll")("PollID"))
'If the user has already voted then redirect them to the results page
If intVotedIDNo = intPollIDNum Then blnAlreadyVoted = True
End If
%>