How to use password in MS Access

Asked By 50 points N/A Posted on -

I want to use a button for password protecting method. Tried out the following code.  But it isn't working properly.

Could you please specify the bugs and could you please handle these?

Thank you million times.

If InputBox("password") = "thepassword" then
Docmd.OpenForm formname
MsgBox "You are not authorized!",vbOKOnly
End if
Private Sub Open_Activities_Menu_Click()
If InputBox("Enter password") = "111111" Then
DoCmd.OpenForm Activities_Menu
MsgBox "You are not authorized!", vbOKOnly
End If
End Sub
The issue is the DoCmd line where I get a message
Run-time error '2494':
The action or method requires a Form Name argument

Your help is very much appreciated,

Thank you.

Best Answer by Milton galo
Best Answer
Best Answer
Answered By 0 points N/A #144955

How to use password in MS Access



Here is the solution for your problem

Just write the code as follow assuming the command button name is Command42


Private sub command42_Click()

 On Error Goto Err_command42_Click

      Dim stDocName As String

      Dim stLinkCritieria As String

If input ("password") ="thepassword" Then

        stDocName="Form Name"

        DoCmd.OpenForm stDocName,,,stLinkCriteria


        MsgBox "You are not Authorized", vbOKOnly

End If


       Exit Sub


      MsgBox Err.Description

      Resume Exit_Command42_Click

End Sub


and It will work with you 

the idea here is to create a button to open form normally using the wizard then you do some changes on it to put the condition of password and make the restriction

Answered By 50 points N/A #144957

How to use password in MS Access



I use MS Access a lot but i want to keep my files safe and locked. So i tried putting passwords but it didn’t work. I really needed a solution for this problem because my files need protection from my "nosy" brother. Thanks to and the expert for solving the issue. You have literally saved my life. Thank you very much. It works 100% now!

Login/Register to Answer

Related Questions