Hello,
I will mention that I am a beginner at Access in every sense of the word. I have created a database for all the training records of my employees. I have set up a login form that requires a password linked to the employee table.
My question is how do I create a command button or action that will prompt the login user and enable them to change their password once they have logged in or chosen a user name from the drop down.
Thank you in advance for the help!
19 8297 MMcCarthy 14,534
Recognized Expert Moderator MVP
Assuming your password is set to a default like "Password".
You don't say if the username is entered freely or chosen from a dropdown list. I'm assuming it's entered freely (txtUser for this example).
In the textbox where the password is entered (txtPassword for this example) create an After Update event using the following code. -
-
Private Sub txtPassword_AfterUpdate()
-
Dim pswd As String
-
Dim confirm As String
-
-
pswd = DLookup("[PasswordField]","TableName", "[UserNameField]='" & Me.txtUser & "')"
-
-
If pswd = "password" Then
-
-
EnterPassword:
-
-
pswd = InputBox "Please enter a new password", "Change Password"
-
confirm = InputBox "Please enter again for confirmation", "Confirm Password"
-
If pswd <> confirm Then
-
MsgBox "Passwords don't match. Please try again.", vbOKOnly
-
GoTo EnterPassword
-
Else
-
DoCmd.RunSQL "UPDATE tablename SET [passwordfield]= '" & Me.pswd & "' WHERE [UserNameField]='" & Me.txtUser & "';"
-
End If
-
Else
-
'Your normal password checking code here
-
End If
-
-
End Sub
-
-
Thank you for your response. I have tried the code, modifying it to match my data and I can't seem to get it to work.
The username is chosen from a dropdown list named Combo10. My textbox for the password entry is named Text12.
I will attach my modified version of the code so you can see what is wrong with it.
I keep getting a syntax error for the line with the DLookup function, as well I forgot to mention in my first message I am using Access 2003.
Also can this code be attached to the OnClick event of the command button that I am using to verify the password and enter the record form?
Thank you for the help.
Here is my code: -
-
Private Sub Text12_AfterUpdate()
-
Dim pswd As String
-
Dim confirm As String
-
-
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]='" & Me.Combo10. & "')"
-
-
If pswd = "password" Then
-
-
EnterPassword:
-
-
pswd = MsgBox "Please enter a new password", "Change Password"
-
confirm = InputBox "Please enter again for confirmation", "Confirm Password"
-
If pswd <> confirm Then
-
MsgBox "Passwords don't match. Please try again.", vbOKOnly
-
GoTo EnterPassword
-
Else
-
DoCmd.RunSQL "UPDATE strEmployees SET [EmpPassword]= '" & Me.pswd & "' WHERE [IngEmpID]='" & Me.Combo10 & "';"
-
End If
-
Else
-
'Check value of password in tblEmployees to see if this
-
'matches value chosen in combo box
-
-
If Me.Text12.Value = DLookup("strEmpPassword", "strEmployees", "[IngEmpID]=" & Me.Combo10.Value) Then
-
-
IngMyEmpID = Me.Combo10.Value
-
-
'Close logon form and open Employee records
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
stDocName = "Read Only Records"
-
-
stLinkCriteria = "[IngEmpID]=" & Me![IngEmpID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Go_Click:
-
Exit Sub
-
-
Else
-
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
-
Me.Text12.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 admin.", vbCritical, "Restricted Access!"
-
Application.Quit
-
End If
-
End If
-
-
End Sub
-
-
Assuming your password is set to a default like "Password".
You don't say if the username is entered freely or chosen from a dropdown list. I'm assuming it's entered freely (txtUser for this example).
In the textbox where the password is entered (txtPassword for this example) create an After Update event using the following code. -
-
Private Sub txtPassword_AfterUpdate()
-
Dim pswd As String
-
Dim confirm As String
-
-
pswd = DLookup("[PasswordField]","TableName", "[UserNameField]='" & Me.txtUser & "')"
-
-
If pswd = "password" Then
-
-
EnterPassword:
-
-
pswd = InputBox "Please enter a new password", "Change Password"
-
confirm = InputBox "Please enter again for confirmation", "Confirm Password"
-
If pswd <> confirm Then
-
MsgBox "Passwords don't match. Please try again.", vbOKOnly
-
GoTo EnterPassword
-
Else
-
DoCmd.RunSQL "UPDATE tablename SET [passwordfield]= '" & Me.pswd & "' WHERE [UserNameField]='" & Me.txtUser & "';"
-
End If
-
Else
-
'Your normal password checking code here
-
End If
-
-
End Sub
-
-
MMcCarthy 14,534
Recognized Expert Moderator MVP
Also can this code be attached to the OnClick event of the command button that I am using to verify the password and enter the record form?
Yes it can.
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]='" & Me.Combo10. & "')"
Firstly, you have a dot after combo10 so remove it.
Secondly, if the value in [lngEmpID] is a number (I suspect it is) then remove single quotes as follows. They are only required when comparing strings.
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10 & ")"
O.K. So, I tried attaching the code to my OnClick event of my command button and I keep getting a Compile Error: syntax error pop up. I also have recieved the message Compile Error: Expected: List Separator or ) when trying to fix it.
I will attach the full code that is attached to my command button -
-
Private Sub Command14_Click()
-
'Check to see if data is entered into the UserName combo box
-
-
If IsNull(Me.Combo10) Or Me.Combo10 = "" Then
-
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
-
Me.Combo10.SetFocus
-
Exit Sub
-
End If
-
-
'Check to see if data is entered into the password box
-
-
If IsNull(Me.Text12) Or Me.Text12 = "" Then
-
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
-
Me.Text12.SetFocus
-
Exit Sub
-
End If
-
-
'Check to see if default password needs to be changed
-
-
Dim cmnd As String
-
Dim confirm As String
-
-
-
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10 & ")"
-
-
If pswd = "Password" Then
-
-
EnterPassword:
-
-
pswd = InputBox "Please enter a new password", "Change Password"
-
confirm = InputBox "Please enter again for confirmation", "Confirm Password"
-
If pswd <> confirm Then
-
MsgBox "Passwords don't match. Please try again.", vbOKOnly
-
GoTo EnterPassword
-
Else
-
DoCmd.RunSQL "UPDATE strEmployees SET [strEmpPassword]= '" & Me.pswd & "' WHERE [IngEmpID]='" & Me.Combo10 & "';"
-
End If
-
Else
-
'Check value of password in tblEmployees to see if this
-
'matches value chosen in combo box
-
-
If Me.Text12.Value = DLookup("strEmpPassword", "strEmployees", "[IngEmpID]=" & Me.Combo10.Value) Then
-
-
IngMyEmpID = Me.Combo10.Value
-
-
'Close logon form and open Employee records
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
stDocName = "Read Only Records"
-
-
stLinkCriteria = "[IngEmpID]=" & Me![IngEmpID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Go_Click:
-
Exit Sub
-
-
Else
-
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
-
Me.Text12.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 admin.", vbCritical, "Restricted Access!"
-
Application.Quit
-
End If
-
-
End Sub
-
Private Sub Command15_Click()
-
On Error GoTo Err_Command15_Click
-
-
-
DoCmd.Close
-
-
Exit_Command15_Click:
-
Exit Sub
-
-
Err_Command15_Click:
-
MsgBox Err.Description
-
Resume Exit_Command15_Click
-
-
End Sub
-
-
Private Sub Text12_AfterUpdate()
-
-
'Check value of password in tblEmployees to see if this
-
'matches value chosen in combo box
-
-
If Me.Text12.Value = DLookup("strEmpPassword", "strEmployees", "[IngEmpID]=" & Me.Combo10.Value) Then
-
-
IngMyEmpID = Me.Combo10.Value
-
-
'Close logon form and open Employee records
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
stDocName = "Read Only Records"
-
-
stLinkCriteria = "[IngEmpID]=" & Me![IngEmpID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Go_Click:
-
Exit Sub
-
-
Else
-
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
-
Me.Text12.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 admin.", vbCritical, "Restricted Access!"
-
Application.Quit
-
End If
-
-
End Sub
-
Yes it can.
Firstly, you have a dot after combo10 so remove it.
Secondly, if the value in [lngEmpID] is a number (I suspect it is) then remove single quotes as follows. They are only required when comparing strings.
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10 & ")"
MMcCarthy 14,534
Recognized Expert Moderator MVP
Sorry this is me again. My brain is dead today
Change ...
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10 & ")"
to ...
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10)
O.K., now I am getting a "Compile error: syntax error" for the line:
pswd = InputBox "Please enter a new password", "Change Password"
Sorry this is me again. My brain is dead today
Change ...
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10 & ")"
to ...
pswd = DLookup("[strEmpPassword]", "strEmployees", "[IngEmpID]=" & Me.Combo10)
MMcCarthy 14,534
Recognized Expert Moderator MVP
O.K., now I am getting a "Compile error: syntax error" for the line:
pswd = InputBox "Please enter a new password", "Change Password"
You left out the brackets
pswd = InputBox ("Please enter a new password", "Change Password")
MMcCarthy 14,534
Recognized Expert Moderator MVP
You left out the brackets
pswd = InputBox ("Please enter a new password", "Change Password")
Or to be more accurate. I left them out.
Sorry...
Mary
now the code stops running at this line with the error message: "method or data member not found" and highlights the pswd part. But the message box is not appearing when I enter the default password, and I am under the impression that it should be appearing regardless of the error in the line below as it occurs after the password would be changed?
DoCmd.RunSQL "UPDATE strEmployees SET [EmpPassword]= '" & Me.pswd & "' WHERE [IngEmpID]='" & Me.Combo10 & "';"
Thanks
Or to be more accurate. I left them out.
Sorry...
Mary
MMcCarthy 14,534
Recognized Expert Moderator MVP
now the code stops running at this line with the error message: "method or data member not found" and highlights the pswd part. But the message box is not appearing when I enter the default password, and I am under the impression that it should be appearing regardless of the error in the line below as it occurs after the password would be changed?
DoCmd.RunSQL "UPDATE strEmployees SET [EmpPassword]= '" & Me.pswd & "' WHERE [IngEmpID]='" & Me.Combo10 & "';"
Thanks
I understood the pswd was the global string variable that the user entered password was stored in. In which case you don't want the Me. part. That is only used for controls on the form.
Mary
Now it executes all the way to the very end, and then there is an error "Block If Without End If" and it highlights the End Sub command, but I can't see where the incongruency in the code is?
Thanks
Charlie
I understood the pswd was the global string variable that the user entered password was stored in. In which case you don't want the Me. part. That is only used for controls on the form.
Mary
MMcCarthy 14,534
Recognized Expert Moderator MVP
Now it executes all the way to the very end, and then there is an error "Block If Without End If" and it highlights the End Sub command, but I can't see where the incongruency in the code is?
Thanks
Charlie
No problem Charlie.
You have to go through all the code when this happens because the compiler can't tell where the error occurred and just goes to the end of the function or procedure.
In your case the following If statement has no End If. -
-
If pswd = "Password" Then
-
EnterPassword:
-
-
pswd = InputBox "Please enter a new password", "Change Password"
-
confirm = InputBox "Please enter again for confirmation", "Confirm Password"
-
If pswd <> confirm Then
-
MsgBox "Passwords don't match. Please try again.", vbOKOnly
-
GoTo EnterPassword
-
Else
-
DoCmd.RunSQL "UPDATE strEmployees SET [strEmpPassword]= '" & Me.pswd & "' WHERE [IngEmpID]='" & Me.Combo10 & "';"
-
End If
-
Else
-
'Check value of password in tblEmployees to see if this
-
'matches value chosen in combo box
-
-
-
Forgive my ignorance, but where would the End If go then?
No problem Charlie.
You have to go through all the code when this happens because the compiler can't tell where the error occurred and just goes to the end of the function or procedure.
In your case the following If statement has no End If. -
-
If pswd = "Password" Then
-
EnterPassword:
-
-
pswd = InputBox "Please enter a new password", "Change Password"
-
confirm = InputBox "Please enter again for confirmation", "Confirm Password"
-
If pswd <> confirm Then
-
MsgBox "Passwords don't match. Please try again.", vbOKOnly
-
GoTo EnterPassword
-
Else
-
DoCmd.RunSQL "UPDATE strEmployees SET [strEmpPassword]= '" & Me.pswd & "' WHERE [IngEmpID]='" & Me.Combo10 & "';"
-
End If
-
Else
-
'Check value of password in tblEmployees to see if this
-
'matches value chosen in combo box
-
-
-
MMcCarthy 14,534
Recognized Expert Moderator MVP
Forgive my ignorance, but where would the End If go then?
Trying to follow your code I would say just before End Sub.
Hmmmm......I put the End If in and now it gives me a run time error 13 mismatch message and in the debugger highlights the line:
pswd = MsgBox("Please enter a new password", "Change Password")
any ideas??
Trying to follow your code I would say just before End Sub.
MMcCarthy 14,534
Recognized Expert Moderator MVP
Hmmmm......I put the End If in and now it gives me a run time error 13 mismatch message and in the debugger highlights the line:
pswd = MsgBox("Please enter a new password", "Change Password")
any ideas??
Where and as what kind of variable have you declared pswd. I don't see it declared in the current code.
Mary
I am not really sure....I have given up on this code and have since taken the "easy" way out and have just created a command button that opens another form that the employees can click. This other form is linked to the password table, so they can change it right in the table via the form. I don't know if this is a good way to do it, but I guess it works for now?
Thanks for your continued help and patience though Mary.
Charlie
Where and as what kind of variable have you declared pswd. I don't see it declared in the current code.
Mary
NeoPa 32,556
Recognized Expert Moderator MVP
Charlie,
So near to the end, is it a good time to give up?
Try posting your whole procedure exactly as it is now for me please.
I'm sure we can get this working for you (well pretty confident anyway).
Some of these syntax problems can be hard to find but I've had some experience with some doozers in my time - lets give it a try.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gill Bates |
last post by:
I'm trying to login to a banking site
(https://www.providentconnection.com) using vb.net. I've tried many
variations of WebClient and HttpWebRequest; none of which I've got to
work. My latest...
|
by: buran |
last post by:
Dear ASP.NET Programmers,
How can I post data to an ASP.NET login page and pass authentication? The
login page uses forms
authentication, users must supply usernames and password and have to...
|
by: David W. Simmonds |
last post by:
I have a form that will prompt for a user name/password. In VS.NET, I have
the protected form in a folder named Admin. I have a Web.config file in that
folder as well. It contains the following...
|
by: 23s |
last post by:
I had this problem in the past, after a server reformat it went away, and
now after another server reformat it's back again - no clue what's doing it.
Here's the flow:
Website root is public, no...
|
by: nicholas |
last post by:
Hi,
Got an asp.net application and I use the "forms" authentication mode defined
in the web.config file.
Everything works fine.
But now I would like to add a second, different login page for...
|
by: pv |
last post by:
Hi everyone,
I need help with following scenario, please:
Users are accessing same web server from intranet (users previously
authenticated in Active Dir) and from extranet (common public...
|
by: Assimalyst |
last post by:
Hi,
I am creating a website where i want to allow some webforms to be
accessible to all users, and those in a subdirectory available only to
authenticated users.
I have created a script to...
|
by: dana lees |
last post by:
Hello,
I am developing a C# asp.net application.
I am using the authentication and authorization mechanism, which its timeout
is set to 60 minutes.
My application consists of 2 frames - a...
|
by: Alan Silver |
last post by:
Hello,
Sorry this is a bit wordy, but it's a pretty simple question...
I have a web site, http://domain/ which is a public site, part of which
(http://domain/a/) is protected by forms...
|
by: satishknight |
last post by:
Hi,
Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |