Multi-User Login Form (1 Viewer)

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
hi All,

I've managed to create a multi-user login form with macro.
user1 is able to login with his password and user2 is able to login with his password. latter I noticed that user1 is able to login with any password in the table and use his previous password to login even after changing it.

can anybody please help.

Thanks in advance.
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
Thanks paul for the response,

the codes are macro how do copy/paste them ?
 

domingsun

Registered User.
Local time
Today, 12:38
Joined
Jun 20, 2013
Messages
46
Hi , Please follow ,

1) Create a Modules named "GVar" and copy this code paste inside.

Option Compare Database
Global strUser As String
Global strRole As String

2)Create 2 text box , User and Password .
-set the User's Text box name to cboUser
-set the Password's Text box name to txtPassword

3)Creat a Login button , set an event in "On Click.
-set the Login button's name to cmdLogin ,
-copy this into the event procedure

Private Sub cmdLogin_Click()
Call Login

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 YOUR USER TABLE
If Me.txtPassword.Value = DLookup("Password", "YOUR USER TABLE", "[UserName]='" & Me.cboUser.Value & "'") Then
DoCmd.Close acForm, "frmLogin", acSaveNo
MsgBox "Welcome, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "WHAT FORM YOU WANT TO OPEN", acNormal, "", "", , acNormal

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 Super Administrator. Ext : 314 " & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If

ErrorHandler:
End Sub
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
thanks domingsunl.

Will try this out. Would it possible for you to post the macro for this that's kinda easier to follow for than VB
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
so do I do all this in the first module ? am new to vba and coding. so please bear with me.
 

domingsun

Registered User.
Local time
Today, 12:38
Joined
Jun 20, 2013
Messages
46
Please download the zipped file .

Inside have all the things you needed.
 

Attachments

  • TestLogin.zip
    152.2 KB · Views: 1,059

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
thanks for the file, what is the password to the Zip file.
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
I guess this should do it. let me check on this.
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
well your login form is perfect.

but I need to change a few. I have the following table
tblEmployee - has the the users with passwords.

and form
LogOverview - the form should open when the authentication is successful

Would really appricate if somebody could get the macro for this.

I've also attached a smaple access database of mine for your reference.
 

Attachments

  • Database2.accdb
    640 KB · Views: 458

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
I've imported ur login form and table and replaced all the fields. now when I loggin with the new form, the names come up correctly but when I type the password it says incorrect, even after changing the passwords in the tblUser.
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
Well after saving and reopening my database solved it all. but I have a form linked to a table tblEmployee that has the Employee name and password. This form is used to change the login password once the user logs in. when I change the password from this form it does not update the table tbleEmployee.

Could you help me on this.
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
Ho Domingsun,

below is the code in macro to evaluate username and password

DLookUp("[EmployeeID]","tblEmployee","[Password]='" & [txtPassword] & "'")

The outcome is like it verifies the username with any password in the password field and not just the one that is repective to the username.

In the db attached, the form frmpasswordChange has the EmployeeName autofilled by a global variable that is set when the login form's EmployeeName is updated.

How can i set the login form to only authenticate the EmployeeName's and his/her respective password and once logged in, the employee should be able to change his password through the frmPasswordChange form.

hope to read from you.
 

Attachments

  • Database1.accdb
    1.8 MB · Views: 266

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:38
Joined
Aug 30, 2003
Messages
36,126
Doing it that way, you'd need to add the employee to the criteria. I do this:

If DLookup("UserPassword", "tblUsers", "UserName = '" & Me.txtUserID & "'") = Me.txtPW Then
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
Thank you for your time pbaldy.

I did try that earlier but it did not work in macro. could you please check on the file that I have edited and edit that in macro and send the same to me or show the equivalent in macro.


Thanks in advance.
 

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
well I tried the same and got the error as in the attached.
 

Attachments

  • dbError.jpg
    dbError.jpg
    68.9 KB · Views: 183

anishkgt

Registered User.
Local time
Today, 22:38
Joined
Nov 4, 2013
Messages
384
hi,

after a little trial and error I've managed to reach somewhere, below is my code

If DLookUp("Password","tblEmployee","txtPassword='" & "'")
Messagebox
Correct

Else
Messagebox
Incorrect


For the above code every time I enter a password I get incorrect password, even when the password is correct in the table tblEmployee

Note:
Password - is the password field in the table tbleEmployee
tblEmployee - is the table containing the UserName and Password
txtPassword - is the form field name for entering the password.
cmbEmployee (not mentioned above) - is where the user enters his name.

Thank a bunch
 

Users who are viewing this thread

Top Bottom