password protect

lipin

Registered User.
Local time
Today, 21:32
Joined
May 21, 2002
Messages
149
Can you password protect just a single command button on a form?
 
yes you can - using VB.

put a text box "text1" on the form (or have the button open a pop up form with a text box) and when the user presses the button, on the on click event, put in an if statement - for example

If Text1 = "password" Then

do whatever.....

Else
MsgBox "wrong password", vbOKCancel

End If
 
I use the below method for a simple way to password protect a command button with an Input Box...

Code:
Private Sub bDeleteRecord_Click()
On Error GoTo Err_bDeleteRecord_Click
    
    Dim strInput As String
    Dim strMsg As String
    
'    Me.tbHidden.SetFocus
    
    Beep
    strMsg = "Please key the Delete Password to allow the deletion of the current record."
    strInput = InputBox(Prompt:=strMsg, Title:="Delete Password")
    If strInput = "[COLOR=red]YourPasswordHere[/COLOR]" Then
        Beep
        DoCmd.RunCommand acCmdDeleteRecord
        Refresh
            Else
            Beep
            MsgBox "Incorrect Password!" & Chr(13) & Chr(13) & "You are not allowed to delete any table records." & Chr(13) & Chr(13) & "Please contact your database administrator for help.", vbCritical, "Invalid Password"
        Exit Sub
    End If
    
'    Me.tbHidden.SetFocus
    
Exit_bDeleteRecord_Click:
    Exit Sub

Err_bDeleteRecord_Click:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_bDeleteRecord_Click

End Sub

'You can not format an Input Box.

'HTH
 

Users who are viewing this thread

Back
Top Bottom