Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Solved: Create a "Change Password" form for Login in Access 2007


(!)

OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
03-May-2012, 10:35 AM #46
Your Password change form doesn't actually need a combo a normal text field would do, then you could have
"[lngEmpID] =" & me.[lngEmpID]

To test the passwords just use something like
if me.password1 <> me.password2 then
msgbox "Sorry Passwords do not match"
me.password2 = ""
me.password2.setfocus
end if
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
03-May-2012, 11:06 AM #47
Haven't had a chance to try that yet. Something is wrong with my VBA...Surprise!!!

This is what I have (what's in red is what Access is highlighting as an error):

Private Sub Command1_Click()
'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 tblEmployees to see if this
'matches value chosen in combo box
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngEmpID]=" & Me.lngEmpID.Value) Then
lngMyEmpID = Me.Str.Value
'Close Change Password Form
DoCmd.Close acForm, "Change Password Form", acSaveYes
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
If Me.password1 <> Me.password2 Then
MsgBox "Sorry 'New Password' and 'Confirm Password' do not match"
Me.password2 = ""
Me.password2.SetFocus
End If
End Sub
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
03-May-2012, 11:13 AM #48
What is me.str?
What was the Error Message?
Where is your Error Trapping?

Why do you need to reset lngMyEmpID anyway?
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
03-May-2012, 11:33 AM #49
I should clarify...I didn't write a word of this. I took some of it from the Login button on the Login form, and then, I just pieced together some things that looked right from a variety of sources (none of which I remember).

So...I have no idea what me.str is. The error message was "Compile Error: Method or data member not found." What is error trapping? And I have no idea why I need to reset lngMyEmpID.
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
03-May-2012, 12:04 PM #50
So just delete that line.
Error trapping is using the OnError event to trap the error and provide an error message, because you don't always get one.
One of the most dangerous things to use in the on error is Resume next as you can get in to all sorts of trouble, it is much better to stop code execution to sort out the error.
__________________
OBP
I do not give up easily
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
04-May-2012, 07:47 AM #51
I deleted the line. Now an error message with the following explanation pops up: "Run-time error '2467': The expression you entered refers to an object that is closed or doesn't exist." It currently highlights "If Me.password1 <> Me.password2 Then"

As far as error trapping goes...do I put that as a separate On Error event for the whole form?
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
04-May-2012, 07:59 AM #52
Do you have fields called Password1 & Password2 to enter the passwords?
The error trap goes in each module, the On error goto errortrap
goes after the Private Sub Command1_Click() line
The rest of goes before the End Sub
Exit Sub
errorcatch:
MsgBox Err.Description
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
04-May-2012, 08:30 AM #53
I think the error message is because I have the form closing after the original password is verified (whoops). If I put Me.password1.SetFocus after the then instead of closing the form, will that be a valid statement?

I will try error trapping as soon as this problem is resolved.
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
04-May-2012, 09:44 AM #54
Um...just noticed today that the audit trail isn't tracking correctly. It isn't tracking all changes to all forms (that have the before update VBA) and it doesn't always recognize who is making the changes.

Thoughts?
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
04-May-2012, 10:09 AM #55
I think I fixed the problem (an error message is no longer popping up). I added the Line MsgBox Err.Description after PrivateSub Command1_Click(). Now I need the VBA to change the original password to the new password in tblEmployees.

I found a code that looks like it might work:
Dim strSQL As String
strSQL = "UPDATE A INNER JOIN B ON A.ID = B.ID SET B.Field1 = <Some value>"
CurrentDb.Execute strSQL, DbFailOnError

Will this work with some alterations to the field references?
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
04-May-2012, 10:10 AM #56
That would be a valid statement.

I am not sure why the audit trail is not working, is there any pattern to the changes it does not register?
The Public Variable to identify the user should be available at all times, unless some other code resets it.
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
04-May-2012, 10:12 AM #57
You can just use a recordset to update password.
krs1716's Avatar
krs1716 krs1716 is offline
Member with 438 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Intermediate
04-May-2012, 10:20 AM #58
The audit trail doesn't seem to recognize who adds a record. It does know who edits a record. On that note, does the audit trail work on continuous forms and/or memo fields?

How would I use a recordset to update the password?
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
04-May-2012, 10:42 AM #59
This piece of code opens a query based on the current Password (it could use the UserID), you would then add a couple of lines of code to edit the Password to new one. You would obviously need to use your Table name.
Dim rs As Object, SQL As String
On Error GoTo Eventerror
SQL = "SELECT ULS.* " & _
"FROM ULS " & _
"WHERE Password = '" & Me.Password & "'"
Set rs = CurrentDb.OpenRecordset(SQL)
If rs.RecordCount = 0 Then

The code to edit the password would be
with rs
.edit
.password = me.password2
.Update
.Bookmark = .LastModified
End With
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,526 posts.
 
Join Date: Mar 2005
Location: UK
04-May-2012, 10:44 AM #60
In the Audit Trail code

If Me.NewRecord Then
action = "Added Record"
With rstable
.AddNew
!UserID = myuserid
!Form = Me.Name
!action = action
![Action Date/Time] = Now()
.Update
.Bookmark = .LastModified
End With
rstable.Close
Set rstable = Nothing
Exit Sub

Add a Message box after the
action = "Added Record"
msgbox "action is " & action
that will tell you if it identifying a New Record correctly

It will only work for a brand new record, once the record is saved any edits will be shown as edited.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑