Multi-User Login Form (2 Viewers)

topdesk123

Registered User.
Local time
Today, 04:14
Joined
Mar 28, 2013
Messages
52
I'm wondering if anyone figured out the incorrect password problem. I am trying to use this code as well, and everytime I get incorrect password...although I've verified it 100 times.

Thank you!
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 21:14
Joined
Jan 20, 2009
Messages
12,852
At home I have a login form built using only macros. It is bound to a table and supports updateable passwords.

I built it just for the exercise in using macros. I normally do everyting in VBA.

I will try to remember to post it tonight.
 

domingsun

Registered User.
Local time
Today, 04:14
Joined
Jun 20, 2013
Messages
46
which login system you want ?
i can help you create 1 ...
please state the function you need ...
something like Login ... Sign up ... Forgot password ...
 

topdesk123

Registered User.
Local time
Today, 04:14
Joined
Mar 28, 2013
Messages
52
Here you go! Thank you!!


Code:
Private Sub cboUser_GotFocus()
     cboUser.Dropdown
        
End Sub
 Private Sub cmdExit_Click()
     Response = MsgBox("Do want to close this application?", vbYesNo + vbQuestion, "Quit Application")
    
    If Response = vbYes Then
        Application.Quit
    End If
 End Sub
 Private Sub cmdLogin_Click()
     Call Login
 End Sub
  
  Private Sub cmdLogin_Enter()
  
      Call Login
  
  End Sub
  
  Public Sub Form_Load()
      
      txtFocus.SetFocus 'txtFocus is a textbox control with height, widht and positions set to zero
      
  End Sub
  
  Public Sub Login()
          
  On Error GoTo ErrorHandler:
  
      If IsNull([cboUser]) = True Then 'Check UserName
          MsgBox "Username is required"
          
      ElseIf IsNull([txtPassword]) = True Then 'Check Password
          MsgBox "Password is required"
          
      Else
      
          'Compare value of txtPassword with the saved Password in tblUser
          If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
              strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
              strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") 'set the value of strRole declared as Global Variable
              DoCmd.Close acForm, "frmLogin", acSaveNo
              MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
  End If
              If strRole = "admin" Then
              DoCmd.OpenForm "adminMenu", acNormal, "", "", , acNormal
              If strRole = "staff" Then
              DoCmd.OpenForm "staffmenu", acNormal
  End If
  
              
          Else
              MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
              intLogAttempt = intLogAttempt + 1
              txtPassword.SetFocus
      
          End If
      
      End If
      
      'Check if the user has 3 wrong log-in attempts and close the application
      If intLogAttempt = 3 Then
          MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
          "Application will exit.", vbCritical, "Restricted Access!"
          Application.Quit
      End If
    
ErrorHandler:
 End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:14
Joined
Aug 30, 2003
Messages
36,126
Are you testing on an admin? I see an issue that might be more clear with proper indenting:

Code:
  If IsNull([cboUser]) = True Then    'Check UserName
    MsgBox "Username is required"

  ElseIf IsNull([txtPassword]) = True Then    'Check Password
    MsgBox "Password is required"
  Else
    'Compare value of txtPassword with the saved Password in tblUser
    If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
      strUser = Me.cboUser.Value    'Set the value of strUser declared as Global Variable
      strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'")    'set the value of strRole declared as Global Variable
      DoCmd.Close acForm, "frmLogin", acSaveNo
      MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
    End If
    If strRole = "admin" Then
      DoCmd.OpenForm "adminMenu", acNormal, "", "", , acNormal
      If strRole = "staff" Then
        DoCmd.OpenForm "staffmenu", acNormal
      End If
    Else
      MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
      intLogAttempt = intLogAttempt + 1
      txtPassword.SetFocus
    End If
  End If
 

topdesk123

Registered User.
Local time
Today, 04:14
Joined
Mar 28, 2013
Messages
52
Sorry, I used a tool called "smart indenter". I didn't realize that problems could be caused by improper indenting.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:14
Joined
Aug 30, 2003
Messages
36,126
I used it too. The problem isn't caused by indenting, just easier to see (to me anyway). The errors are in logic, and there are a couple I see right off. Even if a password is correct, if the user isn't "admin" you're going to get the password error. If the user isn't admin, will the "staff" test ever be made? You need to step through the code as if it were running and follow where it goes for each option.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:14
Joined
Aug 30, 2003
Messages
36,126
Must be somebody at the door. :p

Seriously, dinging when you do what exactly? We're not standing there next to you.
 

anishkgt

Registered User.
Local time
Today, 14:14
Joined
Nov 4, 2013
Messages
384
Hi All,

I've manage to enhance the login form that I've been using except am still not able to verify the username password against the EmployeeName and password in the table tblEmployee. The db file is attached here for anyone's reference who can solve this for me.

I need to verify the username and password against the table in tblEmployee.



Thanks a bunch
 

Attachments

  • InventoryForWeb.accdb
    704 KB · Views: 172

topdesk123

Registered User.
Local time
Today, 04:14
Joined
Mar 28, 2013
Messages
52
I got this to work perfectly. Please excuse if it is not indented correctly :)
Code:
Public Sub Login()
     On Error GoTo ErrorHandler:
     If IsNull([cboUser]) = True Then    'Check UserName is completed
        MsgBox "Username is required"
     ElseIf IsNull([txtPassword]) = True Then    'Check Password is completed
        MsgBox "Password is required"
    
ElseIf Me.txtPassword.Value <> DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
            MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
            intLogAttempt = intLogAttempt + 1
            txtPassword.SetFocus
         End If
    
         'Compare value of txtPassword with the saved Password in tblUser
        'Admin Role
 
        If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
            strUser = Me.cboUser.Value    'Set the value of strUser declared as Global Variable
            strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'")    'set the value of strRole declared as Global Variable
        If strRole = "admin" Then
            DoCmd.OpenForm "adminMenu", acNormal, "", "", , acNormal
DoCmd.Close acForm, "frmLogin", acSaveNo
MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
        
        
         'Staff Role
        
        ElseIf strRole = "staff" Then
        DoCmd.OpenForm "staffmenu", acNormal
       DoCmd.Close acForm, "frmLogin", acSaveNo
        MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
         
End If
End If
     'Check if the user has 3 wrong log-in attempts and close the application
    If intLogAttempt = 3 Then
        MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
               "Application will exit.", vbCritical, "Restricted Access!"
        Application.Quit
    End If
 ErrorHandler:
      
 
      
  
 End Sub
 

anishkgt

Registered User.
Local time
Today, 14:14
Joined
Nov 4, 2013
Messages
384
Thank you topdesk for your reply. Am not much of a programming guy. Was looking a macro reply.

Hope to read a reply. In the mean while i will try to get something out of your code. If you could post the macro or may be edit my db file attached accordingly, that would be even better.

Thanks again.
 

borgi

New member
Local time
Today, 04:14
Joined
May 7, 2014
Messages
5
I have a problem. I have a table Employees (ID, First Name, Last name and User name and password). I also have a table sale, where I as a foreign key employees. What I need is to me that The variable chosen the employee with which you log in and when I save the sale so that the employee table stored in the sale. Here I set the variable in the text box but I need to get my employee has identified the foreign key.
 

domingsun

Registered User.
Local time
Today, 04:14
Joined
Jun 20, 2013
Messages
46
I have a problem. I have a table Employees (ID, First Name, Last name and User name and password). I also have a table sale, where I as a foreign key employees. What I need is to me that The variable chosen the employee with which you log in and when I save the sale so that the employee table stored in the sale. Here I set the variable in the text box but I need to get my employee has identified the foreign key.

That mean you want retrive the foreign key of the logged in staff when your staff key in sale ?
 

borgi

New member
Local time
Today, 04:14
Joined
May 7, 2014
Messages
5
What I need is that when I log in as the user Billy, so when I turn on the form frmSale so in the text box will be Billy and when I add a new record, so Billy will be stored in the table Sale in the username field.
 

Attachments

  • TestLogin11.accdb
    512 KB · Views: 183

anishkgt

Registered User.
Local time
Today, 14:14
Joined
Nov 4, 2013
Messages
384
Ah ok i guess i understand ur requirement. When a user logs in as billy, then on every form his name should appear. For that u have to declare tempvar. And put this temvar as the default value in the text box property.
 

Users who are viewing this thread

Top Bottom