|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Password to open certain reportPlease help me to add a password on opening a specific report.
I want to add a command button that once clicked would ask for a password, when the password is correct it would open a certain report but if the password is wrong a message box will open that advise the user that he cannot open the report. I am trying to do this with VBA but i am having a hard time. Please tell me what to do. When the form is in design view add a command button. In the proc for the
command button's click event put this: On Error GoTo ProcErr DoCmd.OpenReport "secretreport", acViewPreview Exit Sub ProcErr: If Err.Number <> 2501 Then MsgBox Err.Number & vbCrLf & Err.Description End If Err.Clear Change secretreport to the name of your report, save and compile. In the report's module put this: Private Sub Report_Open(Cancel As Integer) On Error GoTo ProcErr Dim strPass As String Const PASS As String = "mypassword" strPass = InputBox("Please enter the password", "Password") If Len(strPass) = 0 Then Cancel = True ElseIf strPass <> PASS Then MsgBox "Sorry, not the right password" Cancel = True End If Exit Sub ProcErr: MsgBox Err.Number & vbCrLf & Err.Description Err.Clear End Sub Change mypassword to your password, save and compile. If you don't make this db an mde or accde, anybody can read the code and find the password in the vba editor. Chris ake wrote: >Please help me to add a password on opening a specific report. >I want to add a command button that once clicked would ask for a password, >when the password is correct it would open a certain report but if the >password is wrong a message box will open that advise the user that he cannot >open the report. > >I am trying to do this with VBA but i am having a hard time. Please tell me >what to do. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-security/200901/1 Hi Chris! Thanks for your help. I don't know why but there must be something
we've missed in there, it didn't work. The report opens but it doesn't ask for a password. Show quoteHide quote "Chris O'C via AccessMonster.com" wrote: > When the form is in design view add a command button. In the proc for the > command button's click event put this: > > On Error GoTo ProcErr > > DoCmd.OpenReport "secretreport", acViewPreview > > Exit Sub > > ProcErr: > If Err.Number <> 2501 Then > MsgBox Err.Number & vbCrLf & Err.Description > End If > Err.Clear > > Change secretreport to the name of your report, save and compile. In the > report's module put this: > > Private Sub Report_Open(Cancel As Integer) > On Error GoTo ProcErr > > Dim strPass As String > Const PASS As String = "mypassword" > > strPass = InputBox("Please enter the password", "Password") > > If Len(strPass) = 0 Then > Cancel = True > ElseIf strPass <> PASS Then > MsgBox "Sorry, not the right password" > Cancel = True > End If > > Exit Sub > > ProcErr: > MsgBox Err.Number & vbCrLf & Err.Description > Err.Clear > End Sub > > > Change mypassword to your password, save and compile. If you don't make this > db an mde or accde, anybody can read the code and find the password in the > vba editor. > > Chris > > > ake wrote: > >Please help me to add a password on opening a specific report. > >I want to add a command button that once clicked would ask for a password, > >when the password is correct it would open a certain report but if the > >password is wrong a message box will open that advise the user that he cannot > >open the report. > > > >I am trying to do this with VBA but i am having a hard time. Please tell me > >what to do. > > -- > Message posted via AccessMonster.com > http://www.accessmonster.com/Uwe/Forums.aspx/access-security/200901/1 > > IIRC Access 97 and 2000 doesn't automatically set the event procedure in the
report's properties when the code is pasted in and saved like it does in newer versions. Open the report in design view and look at the open event. Does it show " [Event Procedure]" - without the quotes? Make sure it does and then save the report. Chris ake wrote: >Hi Chris! Thanks for your help. I don't know why but there must be something >we've missed in there, it didn't work. The report opens but it doesn't ask >for a password. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-security/200901/1 |
|||||||||||||||||||||||