 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 26th, 2007, 07:57 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
using password in Acces
Hi again,
I have another question.
What I would like is to have a form with action buttons (I know how to make them), but when I press one of those buttons, a username and password should be asked before being able to open the next form. I would also like the possibility for the user to change the password if he wants to. What do I have to do to make this work. I guess I have to start making a table with the usernames and a first standard password, but what code should I use to make for acces to check if the password is correct and if the user wants to change the password...
Thanks
|
|

January 26th, 2007, 09:05 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
The button event should NOT open the next form.
You should create an intermediate form, and have two text fields on it, one formatted for passwords so only "****" shows up. Make this form POP-UP and MODAL!!!
Then have a Button on that form to submit the username and password to continue.
Put code on THAT button to go to the Username/Password table (you have one of these, right?) and look up the username, and then check the password against it. If it matches, open the following form. If it doesn't match, tell the user and either keep the current form open, or send them back. This intermediate form should also have a cancel button that opens the first form again.
As to changing the password: create another form with 4 text boxes on it. The text boxes are:
txtUsername - user types in their username
txtOldPassword - user types in old password (password format)
txtNewPass1 - user types in new password (password format)
txtNewPass2 - user types in new password again (password format)
Check to make sure each text box has text in it individually, and then take the values of txtNewPass1 and txtNewPass2 and compare them. If they match, proceed, if not, give the proper warnings and restart.
Then take the username, look it up in the Username table, check the password for accuracy, if it is right, substitute the New password with:
rs("Password") = sNewPass1
rs.Update
Do you need more than this?
mmcdonal
|
|

January 26th, 2007, 06:35 PM
|
|
Friend of Wrox
|
|
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I believe I need more... I'm still not used to write complex code for these kind of things so... (might be easy for you, but is still complex for me, but doing me best to understand the code)
I already created an intermediate form with the name frmBA01. On this form I have 2 text boxes, one for the username and the second for the password. They are called "username" and "password", makes it easy to remember :). Then at the bottom I have an OK and a Cancel button, called cmdOK and cmd Annuleren. The table were the usernames and password comes from is called "tblusernameandpassword" and has the fields "Username" and "Password". Both of them are text-type.
Could you give me the complete code with this information or not for both asking and changing the passwords...
Thanks already for helping.
|
|

January 29th, 2007, 09:47 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Okay, the easiest way for you to do this is to bind the login form to tblusernameandpassword. Then put the username on as a combo box and allow the user to select their name from a list. Put the password field on the form, but hide it. Then put an unbound text box on the form, and on the on click event of the Okay button, put this code:
Dim sPass, sDoc As String
sPass = Me.UboundTextBoxName
If sPass = Me.Password Then
sDoc = "frmNextFormAfterLoginFormName"
Else
MsgBox "Your password is incorrect.", vbCritical
Exit Sub
End If
DoCmd.OpenForm sDoc, acNormal
On the Cancel button, just have it exit the app. (Application.Quit)
Did that work for you?
mmcdonal
|
|

January 29th, 2007, 01:23 PM
|
|
Friend of Wrox
|
|
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just have another question. When I select a username in the combo box, the hidden password field is not updated to the correct password. I tried to make this with a text box and a combo box, but I don't seem to get it updated with the correct password. I guess it can't work with the combo box, because it is hidden and I can't choose the value. How can the value be updated to the correct password instead of keeping the password of the first entry in the table?
Also how do I change the number and letters for the password input into ****?
And how can I use the password change? Following you with the warnings if the new passwords don't match and the restart, but not for changing the old password into the new one... Could you give me some more info on this one too?
Thanks so far for all your help...
|
|

January 29th, 2007, 01:46 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Okay, we were working on the login here.
If the form is bound to the table with the usernames and passwords, create a combo box using the wizard to find a record on your form. Make that the username look up combo box. Hide the regular username field as well. Then hide the password field. This code should work then. The combo box will navigate to the record for the user, and then populate the form with the username and password in the hiddent text boxes.
Be sure to turn off all the controls for the form, and then set it to pop up and modal as well.
Did that work?
mmcdonal
|
|

January 30th, 2007, 11:40 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK, now this works. The only thing left to know is how I can be able to make a password change and how to format the input to password so I don't get for exemple 1234 but ****
|
|

January 30th, 2007, 01:14 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Do this in Table design view. Select the Password field, then select the Input mask, and select Password. Then make sure to propogate this design change down to all your forms.
mmcdonal
|
|

February 6th, 2007, 08:06 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK, back on this topic to be able to change the password. The code is not complete, could you check it and complete where I'm wrong?
Private Sub cmdOK_Click()
Dim spass, sNewPass1 As String
Dim rs As ADODB.Recordset
spass = Me.PasswordInput
sNewPass1 = Me.NewPassword
If IsNull(Me.PasswordInput) Or Me.PasswordInput = "" Then
MsgBox "Gelieve een wachtwoord in te voeren." & vbCrLf & "Veuillez entrer un mot de passe." _
, vbCritical, "Onvoldoende gegevens"
Me.PasswordInput.SetFocus
Exit Sub
ElseIf spass <> Me.Password Then
MsgBox "Het ingevoerde wachtwoord is ongeldig." & vbCrLf & "Le mot de passe n'est pas correcte.", _
vbCritical, "Ongeldige invoer"
Me.PasswordInput.SetFocus
Exit Sub
ElseIf IsNull(Me.NewPassword) Or Me.NewPassword = "" Then
MsgBox "Gelieve een nieuw wachtwoord in te voeren." & vbCrLf & "Veuillez entrer un nouveau mot de passe.", vbExclamation
Me.NewPassword.SetFocus
Exit Sub
ElseIf IsNull(Me.NewPasswordConfirm) Or Me.NewPasswordConfirm = "" Then
MsgBox "Geliev het nieuwe wachtwoord nogmaals in te voeren." & vbCrLf & "Veuillez entrer le nouveau mot de passe une deuxième foi.", vbExclamation
Me.NewPasswordConfirm.SetFocus
Exit Sub
ElseIf Me.NewPassword <> Me.NewPasswordConfirm Then
MsgBox "Het nieuwe wachtwoord is niet 2 maal op dezelfde wijze ingegeven." & vbCrLf & _
"Le Nouveau mot de passe n'a pas été entré de la même façon 2 fois.", vbExclamation
Me.NewPassword.SetFocus
Exit Sub
End If
'open recordset and connection
Set rs = New ADODB.Recordset
'change password
rs.???
rs("Password") = sNewPass1
rs.Update
rs.Close
MsgBox "Het wachtwoord is gewijzigd." & vbCrLf & "Le mot de passe as été changé.", vbInformation
DoCmd.Close acForm, "frmLoginChange"
DoCmd.Maximize
End Sub
The last message box is to tell the user the password had been changed.
|
|
 |