password on form

mccaulj

Registered User.
Local time
Today, 06:47
Joined
Mar 7, 2002
Messages
13
I'm sorry to keep bugging everyone, but now that I have the basic design of my database, I want to keep making it better.

I found some code on another site to make a form that you enter a password into to either open a new form (if correct) or return an error message (if not correct). I am having problems with it. I apologize to those of you who are reading the other site too. I just want to ensure I get an answer.
Here is my code for the form:

Option Compare Database
Option Explicit

Private Sub Cancel_Click()
DoCmd.RunMacro "mcrSwitchboard.OpenSwitch"
End Sub

Private Sub Form_Timer()
'If the Login screen is open for more than 30 seconds, open the switchboard.
DoCmd.RunMacro "mcrSwitchboard.OpenSwitch"

End Sub

Private Sub OK_Click()
If Me.txtPassword = "123" Then
DoCmd.RunMacro "mcrSwitchboard.OpenAdmin2"
Else
MsgBox "The password you entered is incorrect. Please try again or select cancel to return to the switchboard"
DoCmd.close Me
End If

End Sub


The form returns a compile error (ambiguous name) whether I put in the correct password or not. The only two things that work are the cancel button which takes me back to the switchboard and the 30 second default timer which also takes me back to the switchboard.
When I attach the macro OpenAdmin2 to the OK button itself "on click" it works fine. It's just the password thing that it's not dealing with.
Does anyone have any suggestions to what I'm doing wrong??
Thanks!
J.McCaul
 
This answer may not be exactly what you are looking for but it is how I work. I hope my comments are helpful.

I try to avoid using complex code. I like to keep life simple. My way of achieving what you want would be to:

1. Create an unbound text field.
2. Make it a password field by typing Password in the Input Mask property.
3. Put a button next to the unbound field.
4. On the on-click event of the button put the following code:

'This code sets the password as 123abc and assumes the unbound field is called PasswordField.

If Me.PasswordField.Value = "123abc" Then
DoCmd.Openform "MyFormsName"
Else
MsgBox "You need to Enter the correct password to open the form!", vbExclamation + vbOk, "Password Required"
End If

You can put the password (unbound) field and button in a menu, a form or a pop-up form.

Also Access has some good features for password protection. It is worth checking the help-files to find out about them. You can set a database password and user permissions.

Jon
 

Users who are viewing this thread

Back
Top Bottom