Results 1 to 3 of 3
  1. #1
    rcoreejes is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Posts
    6

    Limit times users can login


    Hi, I'm relatively new here and a beginner programmer. Sorry if this question were asked before but my search to this was unsuccessful.
    I have a voting application that need to limit users to only be able to login once to vote.
    Firstly how do you record in a table when a user login and at the login form how do you check to see if the user have logged in previously.
    I have a login form with a username and password fields that work perfectly.

  2. #2
    euanl is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Posts
    25
    Missed bit out of my reply, wait

  3. #3
    euanl is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Posts
    25
    OK, here's what I would do. It may be a bit convoluted but it would work:

    In the table that the votes are logged in create a new column, call it Username

    Reference this in the input form that you use for the user casting votes your voting form (for the remainder of this instruction I will refer to that form as frmVotes, change this to suit) This field should be hidden.

    Create a query attached to the votes table(qryusername) that looks up the hidden text box on your frmVotes, the criterion should be [Forms]![frmVotes]![Username] a second column in the query will be a count of the username, with the criterion being >1 (so it will trigger the query if the username has been entered more than once).

    Now in the ‘After update’ event of the vote field in your votes form enter the following code to check if that user has already logged in, if so it will return a message telling them that they have already voted and politely telling them to bog off (undoes the previous action so the vote is not entered).

    ‘declare your variables
    Dim rst As DAO.Recordset
    Dim qdf As DAO.QueryDef
    Dim prm As DAO.Parameter
    Dim vnotfound As Boolean
    Dim user as String

    ‘This first bit finds the user’s username and enters this into the hidden text box
    user = (Environ$("Username"))
    Me.username.Value = user

    ‘Just ensure that the username is entered into the field.
    Refresh

    ‘This bit checks whether the query is populated and if so then it will do what you want it to do
    Set db = CurrentDb
    Set qdf = db.QueryDefs("qryusername ") ‘The query you created earlier

    For Each prm In qdf.Parameters
    prm.Value = Eval(prm.Name)
    Next

    Set rst = qdf.OpenRecordset

    If Not (rst.BOF And rst.EOF) Then
    vnotfound = True
    Else
    vnotfound = False
    End If

    If vnotfound = True Then
    rst.Close

    'if the list is populated then tell the database what actions you want it to perform,
    ‘In your case you want it to not allow the user to cast a second vote. First give them the message then undo the cast vote action (change to suit your own requirements).


    Msgbox “Sorry, our system detects that you have already cast a vote. Only one vote per candidate, thank you.”

    ‘Undo the action
    Undo

    'then what actions to perform if not populated


    Else:

    'do nothing

    End If

    'always remember to close the bits you have referenced
    Set rst = Nothing
    Set qdf = Nothing
    Set db = Nothing
    Set prm = Nothing

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multi users login form
    By johnwatkins35 in forum Forms
    Replies: 3
    Last Post: 05-15-2012, 11:39 PM
  2. Replies: 4
    Last Post: 12-19-2011, 12:16 PM
  3. Replies: 6
    Last Post: 12-12-2011, 01:28 PM
  4. Replies: 7
    Last Post: 06-24-2011, 10:42 PM
  5. Replies: 1
    Last Post: 01-04-2008, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums