Help with code??????? (1 Viewer)

crann

Registered User.
Local time
Today, 16:12
Joined
Nov 23, 2002
Messages
160
Hi,

I am trying to protect a command button that currently opens a standard mailing list form.

I have read through other Threads, but am new to code, i am using this code to password protect the button:

If InputBox ("Please enter your password.","Password Checkpoint") = "make_up_a_password_to_fill_in_this_space" Then
Do_this_appropriate_action
Else
Invalid_password_action
Exit Sub
End If

I am inserting the above code on the buttons 'on click' event procedure, but there is also the code (below) to open the form, in there and i don't know how the code should read, so that first it asks for a password then if correct opens the form.


Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Mailing List"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

If i insert the code that opens the form in the code above where it says 'do this appropriate action, i get all sorts of compile errors, God knows what i am doing.


Hope someone can understand this. Its blinking confusing.

Thanks Guys.....
 

ghudson

Registered User.
Local time
Today, 11:12
Joined
Jun 8, 2002
Messages
6,195
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 Form Password")
    If strInput = "SpecialFormPassword" Then 'password is correct
        DoCmd.OpenForm "Mailing List"
        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!

HTH
 

Users who are viewing this thread

Top Bottom