Full Version: Modify Northwind 2007 Login Dialog: Cmdlogin: On Click To Included A Password
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
thuzinec
Can anyone tell me how to edit the Macro to include a password in the macro? I know I will need to create a field in my table "Password" and on the Login Dialog form I will need an unbound field "txtPassword" I just don't know how to add this in the Macro.

Thanks!
Terra
mmadani
YOU can Convert your macros to VB, and then

Add an OK button and a Cancel button. Not sure I remember if there is a cancel button. The Cancel button code

should be a close form event

Sub.......

Add behind the cmdlogin button:

If me![TextPassword]<>"Your password goes here" Then

msgbox" You did not provide a valid password",VBOK

Else

'Close the password form code goes here

'Open the desired form or do the next action desired

End if

End Sub


Now if you are trying to provide security for all users with passwords, you'll need a table users with username and password in it. and must check user name and password at login before you proceed.(See Below)
________________________________________________________________________________
_________________________________________________________________________________
______
private sub cmdLogin_Click()

Dim sPswd as string


If IsNull(Me.txtUser) = True or IsNull(Me.txtPswd) = True then
msgbox "Please enter both a userid and password"
exit sub
end if

'DLOOKUP returns null if no record found therefore give it a default value of ""
sPswd = NZ(DLOOKUP("Pswd","tblUsers","UserID='" & Me.txtUser & "'"),"")

If Me.txtPswd <> sPswd then
msgbox "Invalid UserID/Password combination"
exit sub
end if

'Continue with normal successful login code
end sub
________________________________________________________________________________
_________________________________________________


Hope I helped. smile.gif






thuzinec
Hey!

Thank you very much for responding and for your time. I have not had a chance to try it, but when I do I will let you know how it works out.

Terra smile.gif
mmadani
Glad to help any time. I myself have gotten lots of help here.

Mike yw.gif
thuzinec
Hey Mike,

I used your code, made a few modifications and it all works fine with the exception that I wanted to be able to track the User who logged in and any modifications that they made. Before I added the password I was able to open up a form and have it automatically fill in the Current Users name if they were creating a new record and when any thing was modified (data) it would place the name of the person who logged in and the date. This was done by entering in the BeforeUpdate of the initial form this code: DateModified = Date
Me![CreatedBy] = [TempVars]![CurrentUserID]
Me![ModifiedBy] = [TempVars]![CurrentUserID]

But now this does not work. Below is the code I used for the Login form with my modifications.

Button On "frmLogon" Click Event:

Private Sub cmdLogin_Click()

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

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

If Me.txtPassword.Value = DLookup("strEmpPassword", "Employees", "[EmployeeID]=" & Me.cboCurrentEmployee.Value) Then

EmployeeID = Me.cboCurrentEmployee.Value

'Close logon form and open splash screen

DoCmd.CloseForm "frmLogon", acSaveNo
DoCmd.OpenForm "Main"

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 your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub

Can you please advise me where I go from here.......
Thanks so much!
Terra
mmadani
Is there any way you can post your database or a link to it?

Thanks
Mike
thuzinec
Hello Mike,




-One with the password included and the other without. The copy of the one without the password works to include the person who has logged in when he adds a new task and if he makes modifications to someone else's task his name will automatically will be filled in the Modified by field. This you won't see immediately unless you move to another record and go back to the record being modified. The forms you will want to use here is the button labeled "Events, Tasks and Appointments" and then click the "Enter, View, Prt Calendar" - and double click a day to add a task or double click an existing task to modify it to see how this works. I know that this database is in need of "normalization" so no need to point that out, I plan on fixing that. I really need to get this problem worked out, so any help that you can offer I would really be very grateful!

Thanks so much! smile.gif

Terra
thuzinec
Oh, by the way the passwords for each of the employees is Temp1234, but for me Terra L. Huzinec it is Temp123
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.