Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    13

    Unanswered: Login opens different form for different users

    I have a DB set up with a login form (2 unbound fields for username and password) that is using the following code behind a command button to open a single form:

    Private Sub cmdLogin_Click()

    'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.cboEmployee.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 tblUsers to see if this
    'matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblUsers", _
    "[lngEmpID]=" & Me.cboEmployee.Value) Then


    'Close logon form and open user form

    DoCmd.Close acForm, "frmtblEmployees"
    DoCmd.OpenForm "frmAdminAsst"


    Else
    MsgBox "Password Invalid. Please Try Again", 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 admin.", _
    vbCritical, "Restricted Access!"
    Application.Quit
    End If

    However, I would like to open different forms for different users. I have a table of my users, which has a field with the name of the form I want that user to have access to, so I was wanting the code to lookup that form name to know which form to open. ??? Can anyone help with this? Also, I know very minimal VBA, and even less about Access security. Thanks so much!!

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    This code is independent from any Access security. Based on my understanding of your description, I would make the following change:

    Code:
    DoCmd.OpenForm "frmAdminAsst"
    Change the above to:

    Code:
    DoCmd.OpenForm DLookup("strForm", "tblUsers", "[lngEmpID]=" & Me.cboEmployee.Value)
    Change strForm to the name of the field that has the form name in it. This assumes the form name is in the tblUsers table.

  3. #3
    Join Date
    Jul 2009
    Posts
    13

    Talking yipee!!

    you just made me so happy! why couldn't i figure that out???? it works perfectly...thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •