Need Help !!! Login Level to Open different form.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mai Le
    New Member
    • Jun 2007
    • 19

    Need Help !!! Login Level to Open different form.

    Hello Experts.
    Coul you please help me to fix my program.
    I created a login from with 2 levels. Admin an User.
    If Admin login will open A form
    and If User login will open B form

    I had table tblAdmins
    EmpID
    EmpName
    EmpPassword
    Access field for Admin and User Level

    Here is the code
    [CODE=vb]Private Sub cmdLogin_Click( )
    'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEm ployee) 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.txtPa ssword) 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 tblAdmins to see if this matches value chosen in combo box

    If Me.txtPassword. Value = DLookup("EmpPas sword", "tblAdmins" , "[EmpID]=" & Me.cboEmployee. Value) Then

    lngMyEmpID = Me.cboEmployee. Value
    End If


    'Open correct form
    Dim strAccessLevel As String

    strAccessLevel = DLookup("[Access]", "tblAdmins" , "[EmpID]=" & Me.cboEmployee. Value)

    If strAccessLevel = "Admin" Then
    DoCmd.OpenForm "A"
    Else
    If strAccessLevel = "User" Then
    DoCmd.OpenForm "B"
    Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
    Me.txtPassword. SetFocus
    Exit Sub
    End If
    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogonAttempt s = intLogonAttempt s + 1
    If intLogonAttempt s > 3 Then
    MsgBox "You do not have access to this database. Please contact your system administrator." , vbCritical, "Restricted Access!"
    Application.Qui t
    End If
    End Sub
    [/CODE]

    I tried but could not. Please help.

    Thanks in advance
    Last edited by Scott Price; Mar 29 '08, 04:12 PM. Reason: code tags
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    Mai Le,

    Please do not double post. I have deleted your other thread relating to this same question but without the added code.

    Please use the [CODE] tags provided by selecting your code text in this reply window and clicking the # icon on the menu bar of the reply window.

    MODERATOR

    Comment

    • Scott Price
      Recognized Expert Top Contributor
      • Jul 2007
      • 1384

      #3
      What is the problem that you are facing with this code? You need to tell us what doesn't work.

      Regards,
      Scott

      Comment

      • Mai Le
        New Member
        • Jun 2007
        • 19

        #4
        Originally posted by Scott Price
        What is the problem that you are facing with this code? You need to tell us what doesn't work.

        Regards,
        Scott
        Thanks for your support.
        The code is working but somehow put any password in then can open form. another is password stays in password.
        Please help again.
        Thanks
        Have a nice weekend.

        Comment

        • Scott Price
          Recognized Expert Top Contributor
          • Jul 2007
          • 1384

          #5
          Your code looks a little choppy. By this I mean that it doesn't flow correctly from one procedure to the next. Try this:

          [CODE=vb]Private Sub cmdLogin_Click( )

          'Check to see if data is entered into the UserName combo box
          Dim lngMyEmpID As Long
          If IsNull(Me.cboEm ployee) Or Me.cboEmployee = "" Then
          MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
          Me.cboEmployee. SetFocus
          Exit Sub
          End If
          lngMyEmpID = Me.cboEmployee. Value
          'Check to see if data is entered into the password box

          If IsNull(Me.txtPa ssword) 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 tblAdmins to see if this matches value chosen in combo box

          If Me.txtPassword. Value <> DLookup("EmpPas sword", "tblAdmins" , "[EmpID]=" & lngMyEmpID) Then
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
          Me.txtPassword. SetFocus
          Me.txtPassword = Null
          intLogonAttempt s = intLogonAttempt s + 1
          'If User Enters incorrect password 3 times database will shutdown
          If intLogonAttempt s >= 3 Then
          MsgBox "You do not have access to this database. Please contact your system administrator." , vbCritical, "Restricted Access!"
          Application.Qui t
          End If

          Else
          Me.txtPassword = Null
          'Open correct form
          Dim strAccessLevel As String

          strAccessLevel = DLookup("[Admins]", "tblAdmins" , "[EmpID]=" & lngMyEmpID)

          If strAccessLevel = "Admin" Then
          MsgBox "Welcome " & DLookup("EmpNam e", "tblAdmins" , "EmpID=" & lngMyEmpID)
          DoCmd.Close
          DoCmd.OpenForm "A"
          ElseIf strAccessLevel = "User" Then
          MsgBox "Welcome " & DLookup("EmpNam e", "tblAdmins" , "EmpID=" & lngMyEmpID)
          DoCmd.Close
          DoCmd.OpenForm "B"
          End If
          End If

          End Sub[/CODE]

          Regards,
          Scott

          Comment

          • Scott Price
            Recognized Expert Top Contributor
            • Jul 2007
            • 1384

            #6
            This thread is now closed because it is a duplicate of http://www.thescripts.com/forum/show...41#post3135141 .

            I have not deleted this thread because it contains a potential code solution. For all further questions refer to the other thread.

            MODERATOR

            Comment

            Working...