Password on a button to open form

KW99

Registered User.
Local time
Today, 03:44
Joined
Nov 30, 2008
Messages
36
Hi,

I am trying to put a simple password on a command button on a form in order to open another form (if that makes sense).

I have the following code (which I found on another thread)

Private Sub Delmenu1_Click()
On Error GoTo Err_Delmenu1_Click
Retry:
Dim strInput As String
strInput = InputBox("Please Enter the Password", "Enter Password")
If strInputBox = "pass" Then
DoCmd.OpenForm "Frm_Deletions Main", acNormal
Else
If MsgBox("You entered the wrong password. Do you wish to try again?", vbQuestion + vbYesNo, "Password Error") = vbYes Then
GoTo Retry
End If
End If
Exit_Delmenu1_Click:
Exit Sub
Err_Delmenu1_Click:
MsgBox Err.Description
Resume Exit_Delmenu1_Click
End Sub

It will not recognise the password "pass" in this case and just keeps coming up with incorrect password. Can anyone who is better at code than me spot what the problem could be.

Thanks in advance!!!
 
Hi

You defined a string name strInput and in the following statement you are using
Code:
If strInputBox = "pass" Then

So replace strInputBox with strInput and you will get the right result

Cheers
 
Thats great, thanks for the help!!
 
You need to use Option Explicit.
Put those two words at the very top of your module, in the global declarations area.

This will force every variable to be declared, and save you lots of headaches in cases like this.

Evan
 
Hi

You defined a string name strInput and in the following statement you are using
Code:
If strInputBox = "pass" Then

So replace strInputBox with strInput and you will get the right result

Cheers

Whilst the above is correct, I think you can see the pwd as it is typed in. If you use a form and select the Input Mask as Password (one of the options), it replaces the characters you type with * or something similar.

Private Sub txtPassword_AfterUpdate()

Dim stDocName As String
Dim stLinkCriteria As String

strPWord = Me.txtPassword
DoCmd.Close acForm, "frmPassword"

If strPWord = "pass" Then
stDocName = "frmYourFormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End Sub

frmPassword is the name of the form in which you input the pwd.
txtPassword is an unbound text box with the Input Mask set to Password.
frmYourFormName is the form that you want to open upon successful pwd.

To make the security even tighter, go to Code and password protect that - this will stop anyone looking at the VBA code and discovering yr pwd.
 
>> You need to use Option Explicit. <<

I think that gets an "Amen Brother!" ... from me! ...
 

Users who are viewing this thread

Back
Top Bottom