Login Name and Password to Open Form level users.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mai Le
    New Member
    • Jun 2007
    • 19

    Login Name and Password to Open Form level users.

    Hello,
    I used Microsoft Access to create a login form with
    Name
    Password
    Access Level Admin and User

    I would like to let Admin login and open MRB form and User login then open other form like "test"
    Please show me how to do it
    Thanks in advance
    I had code below

    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 tblEmployees 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

    'Close logon form and open splash screen

    DoCmd.Close acForm, "Logon", acSaveNo
    DoCmd.OpenForm "MRB"
    DoCmd.Maximize

    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

    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
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by Mai Le
    Hello,
    I used Microsoft Access to create a login form with
    Name
    Password
    Access Level Admin and User

    I would like to let Admin login and open MRB form and User login then open other form like "test"
    Please show me how to do it
    Thanks in advance
    I had code below

    [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 tblEmployees 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

    'Close logon form and open splash screen

    DoCmd.Close acForm, "Logon", acSaveNo
    DoCmd.OpenForm "MRB"
    DoCmd.Maximize

    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

    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]
    Hello!

    It looks like your code should work. I will attempt to take a stab a it...

    On your form

    (1) You'll need a command button named cmdLogin
    (2) You'll need one textbox named txtPassword
    (3) You'll also need a combobox named cboEmployee

    In your table, named tblAdmins

    (1) You'll need a field named EmpID (links to nothing on form)
    (2) You'll need a field named Employee (links to txtPassword on form)
    (3) You'll need a field named EmpPassword (links to cboEmployee on form)

    Please stay tuned for more, I could have missed something.

    Good luck with project:-)

    Dököll
    Last edited by Dököll; Mar 28 '08, 02:53 AM. Reason: [CODE=VB]

    Comment

    • Mai Le
      New Member
      • Jun 2007
      • 19

      #3
      Originally posted by Dököll
      Hello!

      It looks like your code should work. I will attempt to take a stab a it...

      On your form

      (1) You'll need a command button named cmdLogin
      (2) You'll need one textbox named txtPassword
      (3) You'll also need a combobox named cboEmployee

      In your table, named tblAdmins

      (1) You'll need a field named EmpID (links to nothing on form)
      (2) You'll need a field named Employee (links to txtPassword on form)
      (3) You'll need a field named EmpPassword (links to cboEmployee on form)

      Please stay tuned for more, I could have missed something.

      Good luck with project:-)

      Dököll

      Thank you very much for reply quickly.
      My program is working, I would like to enhance it. Let me explain exact what I want to do again.
      I would like to modify code above. If Admin login will open MRB form and If User login will open TEST form. That is my idea, I tried some way but did not work. Please give me some help for my project. Thanks again.

      Comment

      • Mai Le
        New Member
        • Jun 2007
        • 19

        #4
        Originally posted by Mai Le
        Thank you very much for reply quickly.
        My program is working, I would like to enhance it. Let me explain exact what I want to do again.
        I would like to modify code above. If Admin login will open MRB form and If User login will open TEST form. That is my idea, I tried some way but did not work. Please give me some help for my project. Thanks again.


        Hello,
        I had code below, and did not know how to make it work with Login code.
        Please help. Thanks

        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 tblEmployees 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 "MRB"
        Else
        If strAccessLevel = "User" Then
        DoCmd.OpenForm "TEST"
        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

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          #5
          Originally posted by Mai Le
          Hello,
          I had code below, and did not know how to make it work with Login code.
          Please help. Thanks
          [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 tblEmployees 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 "MRB"
          Else
          If strAccessLevel = "User" Then
          DoCmd.OpenForm "TEST"
          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]
          Greetings and salutations Mai Le!

          Hope your week-end plans are in order...

          I added some code tags for ya for readibility. Loooks like I switched some things around on you, Mai Le:

          (1) You'll need a field named EmpID (links to nothing on form)
          (2) You'll need a field named EmpPassword (links to txtPassword on form)
          (3) You'll need a field named Employee (links to cboEmployee on form)

          Did you try this option? Works on my machine:-) I should perhaps mention I did figure out that EmpID is linked to the form's lngMyEmpID field if that helps...

          Do you have a table with the fields mentioned. Tell us and we shall continue, no problem.

          In a bit!

          Dököll
          Last edited by Dököll; Mar 29 '08, 04:37 PM. Reason: text...

          Comment

          • Mai Le
            New Member
            • Jun 2007
            • 19

            #6
            Originally posted by Dököll
            Greetings and salutations Mai Le!

            Hope your week-end plans are in order...

            I added some code tags for ya for readibility. Loooks like I switched some things around on you, Mai Le:

            (1) You'll need a field named EmpID (links to nothing on form)
            (2) You'll need a field named EmpPassword (links to txtPassword on form)
            (3) You'll need a field named Employee (links to cboEmployee on form)

            Did you try this option? Works on my machine:-) I should perhaps mention I did figure out that EmpID is linked to the form's lngMyEmpID field if that helps...

            Do you have a table with the fields mentioned. Tell us and we shall continue, no problem.

            In a bit!

            Dököll

            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

              #7
              Mai Le,

              I have already warned you once to not double post. I see that this is the first thread you posted about this exact same question. Here is a link to the duplicate posting.

              Double posting consumes resources and causes confusion. If it happens again it will result in a temporary ban of 1 week.

              MODERATOR

              Comment

              • Mai Le
                New Member
                • Jun 2007
                • 19

                #8
                Originally posted by Scott Price
                Mai Le,

                I have already warned you once to not double post. I see that this is the first thread you posted about this exact same question. Here is a link to the duplicate posting.

                Double posting consumes resources and causes confusion. If it happens again it will result in a temporary ban of 1 week.

                MODERATOR
                Hi Scott,
                Sorry for confusing, I'm still new in this forum. I tried to learn and understand in urgent. Please ignore this post and delete it if needed. Thanks for your help. You are greatly help. Your code is working in my program. Thank you very much!!
                That took me a week to think and figure out how it work. I took your code and applied to my program. It's wonderful.

                Mai Le

                Comment

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

                  #9
                  No problem, Mai Le I understand that things can be confusing.

                  Glad the code is working for you!

                  Good luck on the rest of your application.

                  Regards,
                  Scott

                  Comment

                  Working...