How to change a password in a form?

  • Thread starter alhindson via AccessMonster.com
  • Start date
A

alhindson via AccessMonster.com

I used the code below (found in another thread) to create a password
protected form...it works great...However (here's where I feel like an idiot).
If I want to change the password from PASSWORD where can I do that?
I've tried in the tblPassword under KeyCode (honestly not sure why Key Code
"2818" works)-but I can't change it to an actual password.
And i've tried it under the input mask of my textbox text0 didn't work?

I know what an idiot--but would appreciate ANY help!!
Thanks
Laurie



In the module sheet, type the following procedure:public MyPassword
Public Function KeyCode(Password As String) As Long
' This function will produce a unique key for the
' string that is passed in as the Password.
Dim I As Integer
Dim Hold As Long

For I = 1 To Len(Password)
Select Case (Asc(Left(Password, 1)) * I) Mod 4
Case Is = 0
Hold = Hold + (Asc(Mid(Password, I, 1)) * I)
Case Is = 1
Hold = Hold - (Asc(Mid(Password, I, 1)) * I)
Case Is = 2
Hold = Hold + (Asc(Mid(Password, I, 1)) * _
(I - Asc(Mid(Password, I, 1))))
Case Is = 3
Hold = Hold - (Asc(Mid(Password, I, 1)) * _
(I + Len(Password)))
End Select
Next I
KeyCode = Hold
End Function


5. Press ALT+F11 to return to Access.
6. In the Database window, under Objects, click Tables, and then click New.
7. In the New Table dialog box, double-click Design View.
8. Create a new table as follows: Table: tblPassword
---------------------------
Field Name: ObjectName
Data Type: Text
Field Size: 50
Field Name: KeyCode
Data Type: Text
Field Size: 25
Input Mask: Password

Table Properties: tblPassword
-----------------------------
PrimaryKey: ObjectName


9. Open the tblPassword table and then enter the following data:
ObjectName: Orders
KeyCode: 2818


10. Create a new form in design view and save the form as frmPassword.
11. Add a single textbox to frmPassword called Text0, and a command button
called CheckPassword.
12. Set the Input Mask property of Text0 to "PASSWORD" (minus the quotation
marks).
13. Add the following code to the OnClick Event of the CheckPassword button
and then save the form:If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
MyPassword = Me!Text0.Value
DoCmd.Close acForm, "frmPassword"
End If


14. Open the Orders form in Design view.
15. If the property sheet is not visible, click Properties on the View menu.
16. Type the following event procedure in the module for the OnOpen property
of the form:private Sub Form_Open(Cancel as Integer)
Dim Hold As Variant
Dim tmpKey As Long
Dim I As Integer
Dim rs As DAO.Recordset
Dim db As DAO.Database

On Error GoTo Error_Handler
' Prompt the user for the Password.
DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
Hold = MyPassword
' Open the table that contains the password.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
rs.Index = "PrimaryKey"
rs.Seek "=", Me.Name
If rs.NoMatch Then
MsgBox "Sorry cannot find password information. Try Again"
Cancel = -1
Else
' Test to see if the key generated matches the key in
' the table; if there is not a match, stop the form
' from opening.
If Not (rs![keycode] = KeyCode(Cstr(Hold))) Then
MsgBox "Sorry you entered the wrong password." & _
"Try again.", vbOKOnly, "Incorrect Password"
Cancel = -1
End If
End If
rs.Close
db.Close
Exit Sub

Error_Handler:
MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
Exit Sub
End Sub
 
J

Jeff Conrad [MSFT]

Hi Laurie,

Assuming you have done everything correctly, open the module in Design View
and then go to the immediate window by using CTRL-G on the keyboard.

Type this line of code in the immediate window:

?KeyCode("mypassword")

Where mypassword is the whatever password you would like to have. Press
Enter.

- A number will be displayed so write it down.
- Close the module.
- Open up the table that you created for this and enter that number into the
field called KeyCode (The password mask will hide the actual number you type
in.)
- The password should now be changed.

--
Jeff Conrad - Access Junkie - MVP Alumnus
SDET - XAS Services - Microsoft Corporation

Co-author - Microsoft Office Access 2007 Inside Out
Presenter - Microsoft Access 2007 Essentials
http://www.accessmvp.com/JConrad/accessjunkie.html
Access 2007 Info: http://www.AccessJunkie.com

----------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.mspx
----------

in message:
I used the code below (found in another thread) to create a password
protected form...it works great...However (here's where I feel like an
idiot).
If I want to change the password from PASSWORD where can I do that?
I've tried in the tblPassword under KeyCode (honestly not sure why Key
Code
"2818" works)-but I can't change it to an actual password.
And i've tried it under the input mask of my textbox text0 didn't work?

I know what an idiot--but would appreciate ANY help!!
Thanks
Laurie



In the module sheet, type the following procedure:public MyPassword
Public Function KeyCode(Password As String) As Long
' This function will produce a unique key for the
' string that is passed in as the Password.
Dim I As Integer
Dim Hold As Long

For I = 1 To Len(Password)
Select Case (Asc(Left(Password, 1)) * I) Mod 4
Case Is = 0
Hold = Hold + (Asc(Mid(Password, I, 1)) * I)
Case Is = 1
Hold = Hold - (Asc(Mid(Password, I, 1)) * I)
Case Is = 2
Hold = Hold + (Asc(Mid(Password, I, 1)) * _
(I - Asc(Mid(Password, I, 1))))
Case Is = 3
Hold = Hold - (Asc(Mid(Password, I, 1)) * _
(I + Len(Password)))
End Select
Next I
KeyCode = Hold
End Function


5. Press ALT+F11 to return to Access.
6. In the Database window, under Objects, click Tables, and then click
New.
7. In the New Table dialog box, double-click Design View.
8. Create a new table as follows: Table: tblPassword
---------------------------
Field Name: ObjectName
Data Type: Text
Field Size: 50
Field Name: KeyCode
Data Type: Text
Field Size: 25
Input Mask: Password

Table Properties: tblPassword
-----------------------------
PrimaryKey: ObjectName


9. Open the tblPassword table and then enter the following data:
ObjectName: Orders
KeyCode: 2818


10. Create a new form in design view and save the form as frmPassword.
11. Add a single textbox to frmPassword called Text0, and a command button
called CheckPassword.
12. Set the Input Mask property of Text0 to "PASSWORD" (minus the
quotation
marks).
13. Add the following code to the OnClick Event of the CheckPassword
button
and then save the form:If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
MyPassword = Me!Text0.Value
DoCmd.Close acForm, "frmPassword"
End If


14. Open the Orders form in Design view.
15. If the property sheet is not visible, click Properties on the View
menu.
16. Type the following event procedure in the module for the OnOpen
property
of the form:private Sub Form_Open(Cancel as Integer)
Dim Hold As Variant
Dim tmpKey As Long
Dim I As Integer
Dim rs As DAO.Recordset
Dim db As DAO.Database

On Error GoTo Error_Handler
' Prompt the user for the Password.
DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
Hold = MyPassword
' Open the table that contains the password.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
rs.Index = "PrimaryKey"
rs.Seek "=", Me.Name
If rs.NoMatch Then
MsgBox "Sorry cannot find password information. Try Again"
Cancel = -1
Else
' Test to see if the key generated matches the key in
' the table; if there is not a match, stop the form
' from opening.
If Not (rs![keycode] = KeyCode(Cstr(Hold))) Then
MsgBox "Sorry you entered the wrong password." & _
"Try again.", vbOKOnly, "Incorrect Password"
Cancel = -1
End If
End If
rs.Close
db.Close
Exit Sub

Error_Handler:
MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
Exit Sub
End Sub
 
A

alhindson via AccessMonster.com

Jeff---You da' MAN!!
It worked Perfect!! THANKS!!!!
Hi Laurie,

Assuming you have done everything correctly, open the module in Design View
and then go to the immediate window by using CTRL-G on the keyboard.

Type this line of code in the immediate window:

?KeyCode("mypassword")

Where mypassword is the whatever password you would like to have. Press
Enter.

- A number will be displayed so write it down.
- Close the module.
- Open up the table that you created for this and enter that number into the
field called KeyCode (The password mask will hide the actual number you type
in.)
- The password should now be changed.
I used the code below (found in another thread) to create a password
protected form...it works great...However (here's where I feel like an
[quoted text clipped - 113 lines]
Exit Sub
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top