Results 1 to 3 of 3
  1. #1
    Addanny's Avatar
    Addanny is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    15

    Login Form/User ID Trouble.

    I am sort of new to this whole Access thing. I use Access 2007 and I have a login form for a table. I have three fields in the table UserID, Username and Password. I have a form that has the following code for user login:

    Option Compare Database
    Private intLogonAttempts As Integer
    Private Sub cmdLogin_Click()
    'Check to see if data is entered into the Username combo box
    If IsNull(Me.cboUsername) Or Me.cboUsername = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.cboUsername.SetFocus
    Exit Sub
    End If


    'Check to see if data is entered into the password box
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
    MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
    Me.txtPassword.SetFocus
    Exit Sub
    End If
    'Check value of password in tblLogin to see if this matches value chosen in combo box
    If Me.txtPassword.Value = DLookup("Password", "tblLogin", "[UserID]=" & Me.cboUsername.Value) Then
    MyUserID = Me.cboUsername.Value
    'Close logon form and open splash screen
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmMain"
    Else
    MsgBox "Password Invalid. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry!"
    Me.txtPassword.SetFocus
    End If
    'If User Enters incorrect password 3 times database will shutdown
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
    MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
    Application.Quit
    End If
    End Sub

    Private Sub cmdCancel_Click()
    DoCmd.Quit
    End Sub


    Problem is:


    When I log a user in I would like them to see only records that they created and not anyone else's. Subsequent tables have a field "EnteredBy" which works just fine. If I enter data manually the records do show up under the correct User ID in relation to EnteredBy field. How do I make records show up on a form, only those created by the specific user?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If you have an enteredBy field in each record, you could change the record source of the form along these lines

    ...whatever the form is
    Me.recordsource = "select * from YourQuery or Table where EnteredBy = " & the validated Username/Id entered the User
    Me.Requery

    I'm sure it could be more complex that this, but I think this would be a general approach.
    If Forms are Bound, then adjust the recordsource to only allow records for the current user.

    Good luck

  3. #3
    Addanny's Avatar
    Addanny is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    15
    Lol thanx for the prompt response orange. Sorry have been up to my neck in a laptop deployment for the last month or so. Just getting back in the swing of things here. I got this one done.

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

Similar Threads

  1. HELP>Access 2010 User Login Form Code.
    By zaaimanm in forum Programming
    Replies: 5
    Last Post: 10-22-2012, 07:28 PM
  2. User Login Form
    By glen in forum Forms
    Replies: 21
    Last Post: 09-17-2012, 09:09 AM
  3. Having trouble visualizing how to create a login
    By seth.murphine in forum Access
    Replies: 19
    Last Post: 04-11-2012, 03:24 PM
  4. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  5. Replies: 3
    Last Post: 09-22-2011, 03:35 PM

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