Password on a Report

  • Thread starter Thread starter bermetj
  • Start date Start date
B

bermetj

I have a switchboard and want to password protect one of the reports.
So Switchboard opens a form (frm Password) which has a text field for
password (txt Password). If password is correct report opens, if
incorrect it gives a message box saying that the pasword is incorrect,
please try again. However when I am trying to close the form, it gives
me a run-time error 2585. Here is the code. Thank you!

Private Sub cmd_Submit_Enter()
Dim strPassword As String

strPassword = Me![txt Password]

If strPassword = "emergency" Then
DoCmd.OpenReport "rpt Emergency Posting", acViewPreview
Else
MsgBox ("The password you entered is incorrect, please try again.")
Me![txt Password] = Null
End If

DoCmd.close acForm, "frm Password"

End Sub
 
I have a switchboard and want to password protect one of the reports.
So Switchboard opens a form (frm Password) which has a text field for
password (txt Password). If password is correct report opens, if
incorrect it gives a message box saying that the pasword is incorrect,
please try again. However when I am trying to close the form, it gives
me a run-time error 2585. Here is the code. Thank you!

Private Sub cmd_Submit_Enter()
Dim strPassword As String

strPassword = Me![txt Password]

If strPassword = "emergency" Then
DoCmd.OpenReport "rpt Emergency Posting", acViewPreview
Else
MsgBox ("The password you entered is incorrect, please try again.")
Me![txt Password] = Null
End If

DoCmd.close acForm, "frm Password"

End Sub

Have you check the events on the form "frm Password"?
Error Description -
"This action can't be carried out while processing a form or report event.
A macro specified as the OnOpen, OnClose, OnFormat, OnRetreat, OnPage,
or OnPrint property setting contains an invalid action for the property.
When you click OK, an Action Failed dialog box will display the name of the
macro that failed and its arguments."
 
The full error I get looks like following:

~~~~~~~~~~~~~
Run-time error '2585'

This action can't be carried out while processing a form or report
event.

A macro specified as the OnOpen, OnClose, OnFormat, OnRetreat, OnPage,
or OnPrint property setting contains an invalid action for the
property.

When you click OK, an Action Failed dialog box will display the name of
the
macro that failed and its arguments."
~~~~~~~~~~~~~~

However the button provided are only "Debug", "End" and "Help".
Pressing on "Debug" button takes me to VBA code to line:

DoCmd.close acForm, "frm Password"

I check and I don't have any macros or functions associated with form
"frm Password". Why do I get this error? Thank you!
 
I resolved it. Other posts on similar problem gave me an idea on how to
work around the error.
I removed this line from "frm Password"
DoCmd.close acForm, "frm Password"
and put it in the report's onClose event.

Here is the code on the form "frm Password"
~~~~~~~~
Private Sub cmd_Submit_Enter()
Dim strPassword As String

strPassword = Me![txt Password]

If strPassword = "emergency" Then
DoCmd.OpenReport "rpt Emergency Posting", acViewPreview
Else
MsgBox ("The password you entered is incorrect, please try again.")
Me![txt Password] = Null
End If

End Sub
~~~~~~~~


And here is the code from report's onClose event:
~~~~~~~~
Private Sub Report_Close()
DoCmd.close acForm, "frm Password"
End Sub
~~~~~~~~
 
Back
Top