password protect a form

hmongie

Registered User.
Local time
Today, 23:54
Joined
May 17, 2003
Messages
99
sorry if i'm taking up space but i couldn't find anything concrete during my search.

I just want to create a command button which opens a form. With an input box that asks for a password. If the right password is inputted, then it opens up a form, else it displays a msg.

I looked a one of the sample ones, but on that sample, there was no option of canceling the input form once it is opened. If someone can, please point me in the right direction.

Thanks, sorry for taking up space.
 
I assume you are not using Access security?
 
I have this code on a small popup form....

Code:
Private Sub Command2_Click()
    Set con = Application.CurrentProject.Connection
    Set rs = CreateObject("ADODB.Recordset")
    stSql = "SELECT * FROM tblpassword "
    'I have the password stored in this table!

    rs.Open stSql, con, 1    ' 1 = adOpenKeyset
    
    If Not (rs.EOF) Then
        If rs![PASSWORD] = Form_PASSWORD.Text0.Value Then
               'Text0 is my unbound box for the user to enter the password!
            DoCmd.OpenForm "frmMainData"
            DoCmd.OpenForm "PASSWORD"
            DoCmd.Close
            Else
            MsgBox "You have entered the wrong Password!"
        End If
    End If
End Sub
 
I forgot you wanted to be able to cancel also...
Put this on your cancel button.....of course your name "Command3_Click()" would be different...

Code:
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
    DoCmd.Close

Exit_Command3_Click:
    Exit Sub

Let me know if you ned further help. If your on a network theres other options, especially if you have an employees table... Thats what KenHigg probably is eluding to...
 
Sonny, Would users be able to hack into this table?
 
Yep.... Thats why I refered back to your post... I also provide away for the folks that really use my db to lookup the password, I just created a hidden label on my statup form that displays the password if you know where to click. But I just changed the startup to check my employee table against the NTUserID and by-pass the password form altogether if a match. This method keeps the honest out. Other than that, very hackable!
 
You can hardcode the password in the VBA. The user will not be able to see it if you convert your MDB to a MDE or use Access security.

This is a simple way to call an input box that allows the user to key a password and if correct it will open a form. Assign this code to the OnClick event of the button to open the form that you want password protected.

Code:
    Dim strInput As String
    Dim strMsg As String
    
    Beep
    strMsg = "This form is used only by the ''Special Form'' people." & vbCrLf & vbLf & "Please key the ''Special Form'' password to allow access."
    strInput = InputBox(Prompt:=strMsg, title:="Special Password")
    If strInput = "SpecialFormPassword" Then 'password is correct
        DoCmd.OpenForm "YourSpecialFormNameHere"
        DoCmd.Close acForm, Me.Name
    Else 'password is incorrect
        MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
        Exit Sub
    End If
You can not format an Input Box. You will have to create a custom form if you want to hide the ''keyed'' password with ******.


HTH
 
Password

Thanx for the posts,

But I don't have a table. Is there a way to create a form, then place some code into a command button to verified the text that was inputted in the input field.

For example: If password in text1 = "hey dude" then open myform else display message "sorry dude, wrong password".

Nothing too fancy. Just so that the input is in ******* . I know that part, but it's just writing the codes for it that I don't know how to do.

Any help thanks.
 
This should do what you need

Private Sub CmdOpenResFrm_Click()

Dim strPasswd

strPasswd = InputBox("Enter Password", "Restricted Form")

If strPasswd = "your password" Then

DoCmd.OpenForm "FrmName", acNormal

Else

MsgBox "Your Message"

Exit Sub

End If

End Sub
 
my example

Okay, this is what i am working on. If anybody can help me, please give it a shot. I am trying to get the password form to work so that when the right password is inputted into the input text field it will open the "teachersection". If a wrong password is entered, then a msg will open and say "wrong password".


Thanks everyone. My sample db is attached.
 

Attachments

Try this

Private Sub cmdopenresform_Click()

Dim strPasswd

strPasswd = Textboxname

If strPasswd = "password" Then

DoCmd.OpenForm "teachersection", acNormal

Else

MsgBox "Incorrect password"

Exit Sub

End If

End Sub
 
I can not open you attachment but this will work for testing a text box from the OnClick event of a command button...
Code:
If Me.[YourTextBox] = "YourPassword" Then
	DoCmd.OpenForm "YourFormName", acNormal
Else
        MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
End If
 
hey ghudson,

Nice post. It worked like a charm. I got it working good. Only one thing though. Is there a way to make it close after the form is opened. I'm using having the opened form execute a macro to close the pw form but is there another way to close the form after it's executed? If so let me know.


Thanx so much. Once again, you helped me.
 
DoCmd.Close acForm, Me.Name

That is the command you want to use to close the form that the code is run from [as nyoman stated]. I had that command as a part of my routine in my first post above.
 
I'm assuming that the DoCmd.Close ... line goes right under the DoCmd.Open .... line . Let me know if this is correct.. thanx..
 
hmongie said:
I'm assuming that the DoCmd.Close ... line goes right under the DoCmd.Open .... line . Let me know if this is correct.. thanx..
Yes.
Code:
    Dim strInput As String
    Dim strMsg As String
    
    Beep
    strMsg = "This form is used only by the ''Special Form'' people." & vbCrLf & vbLf & "Please key the ''Special Form'' password to allow access."
    strInput = InputBox(Prompt:=strMsg, title:="Special Password")
    If strInput = "SpecialFormPassword" Then 'password is correct
        DoCmd.OpenForm "YourSpecialFormNameHere"
        DoCmd.Close acForm, Me.Name
    Else 'password is incorrect
        MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
        Exit Sub
    End If
 
--------------------------------------------------------------------------
If Me.[YourTextBox] = "YourPassword" Then
DoCmd.OpenForm "YourFormName", acNormal
Else
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
End If
--------------------------------------------------------------------------
Hi G Hudson,

How are you doing m8?

I have managed to incorporate the code you supplied above onto my forms with great success, but can I ask, Is there a way in which I can add a few more different passwords on the form so that it would open "yourformname"?

Kind regards m8
 
Is this what you want?
Code:
If [YourTextBox] = "YourPassword1" Then
    DoCmd.OpenForm "YourFormName1", acNormal
ElseIf [YourTextBox] = "YourPassword2" Then
    DoCmd.OpenForm "YourFormName2", acNormal
ElseIf [YourTextBox] = "YourPassword3" Then
    DoCmd.OpenForm "YourFormName3", acNormal
Else
    MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
End If
Or this...
Code:
If [YourTextBox] = "YourPassword1" Or [YourTextBox] = "YourPassword2" Or [YourTextBox] = "YourPassword3" Then
    DoCmd.OpenForm "YourFormName", acNormal
Else
    MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
End If
 
--------------------------------------------------------------------------
If [YourTextBox] = "YourPassword1" Then
DoCmd.OpenForm "YourFormName1", acNormal
ElseIf [YourTextBox] = "YourPassword2" Then
DoCmd.OpenForm "YourFormName2", acNormal
ElseIf [YourTextBox] = "YourPassword3" Then
DoCmd.OpenForm "YourFormName3", acNormal
Else
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''Special Form''.", vbCritical, "Invalid Password"
End If
--------------------------------------------------------------------------
Hi GHudson.

The above example you provided, worked perfectly. Thanx so much.

Regards
Charlie
 

Users who are viewing this thread

Back
Top Bottom