Button to open Reports

B

Bonnie

Hi there! Using A02 on XP. Have queried records meeting
criteria for Reminder1 reports. Each belongs to a pricing
structure SA02, SA03 or SA04. May be 23 of one, 5 of
another or even zero. Reminder1 has a report for each
pricing structure (old story). Each report's OnNoData
event shows a message and the report doesn't open if there
are no records for that reminder.

My form has a button (see code below). Problem is this: if
the first or second report has zero records, you get the
nice little message about NoData but as soon as you click
Okay, you get the OpenReportActionCancelled goodie and
even if the next report in line has data, you are out of
luck. How can I put something like the OnNoData code in my
button's OnClick event so it will move to the next report?

Luv U Guys, 1 N All. Always been a great help to me.
Thanks in advance for any help or advice.

Private Sub Rem1_Click()
If CurrentUser() <> "BWA" And CurrentUser() <> "PLG"
And CurrentUser() <> "VRS" Then
MsgBox "You are not authorized to open these reports."
DoCmd.Close
Else
On Error GoTo Err_Rem1_Click

Dim stDocName As String

stDocName = "RPSAdminFeeBillReminder1SA02"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom75

stDocName = "RPSAdminFeeBillReminder1SA03"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom75

stDocName = "RPSAdminFeeBillReminder1SA04"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom75

Exit_Rem1_Click:
Exit Sub

Err_Rem1_Click:
MsgBox Err.Description
Resume Exit_Rem1_Click
End If
End Sub
 
M

Marshall Barton

Bonnie said:
Hi there! Using A02 on XP. Have queried records meeting
criteria for Reminder1 reports. Each belongs to a pricing
structure SA02, SA03 or SA04. May be 23 of one, 5 of
another or even zero. Reminder1 has a report for each
pricing structure (old story). Each report's OnNoData
event shows a message and the report doesn't open if there
are no records for that reminder.

My form has a button (see code below). Problem is this: if
the first or second report has zero records, you get the
nice little message about NoData but as soon as you click
Okay, you get the OpenReportActionCancelled goodie and
even if the next report in line has data, you are out of
luck. How can I put something like the OnNoData code in my
button's OnClick event so it will move to the next report?

Luv U Guys, 1 N All. Always been a great help to me.
Thanks in advance for any help or advice.

Private Sub Rem1_Click()
If CurrentUser() <> "BWA" And CurrentUser() <> "PLG"
And CurrentUser() <> "VRS" Then
MsgBox "You are not authorized to open these reports."
DoCmd.Close
Else
On Error GoTo Err_Rem1_Click

Dim stDocName As String

stDocName = "RPSAdminFeeBillReminder1SA02"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom75

stDocName = "RPSAdminFeeBillReminder1SA03"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom75

stDocName = "RPSAdminFeeBillReminder1SA04"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom75

Exit_Rem1_Click:
Exit Sub

Err_Rem1_Click:
MsgBox Err.Description
Resume Exit_Rem1_Click
End If
End Sub


YOu can catch the 2501 error in your error handler code.

Note that you xan not place the error handler code inside
the If Else End If. Try using this kind of structure:

If CurrentUser() <> "BWA" _
And CurrentUser() <> "PLG" _
And CurrentUser() <> "VRS" Then
MsgBox "You are not authorized to open these reports."
DoCmd.Close
Emd If

On Error GoTo Err_Rem1_Click
Dim stDocName As String
. . .
Exit_Rem1_Click:
Exit Sub

Err_Rem1_Click:
Select Case Err.Number
Case 2501
Resume Next
Case Else
MsgBox Err.Description
Resume Exit_Rem1_Click
End Select
End Sub
 
B

Bonnie

Marsh! I saw your name and just knew I was in for a treat!
It works beautifully!!! It was just needing a few extra
brain cells on the J-O-B. Thanks so much for taking the
time to respond. Always a pleasure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top