By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,868 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Tried Solutions from Post - Problem Error 2501 still exists

P: n/a
I have a report that runs fine with data. If there is no data, I have
its NO Data event sending a MsgBox and cancelling the report.

Then it seems I still get the 2501 message on the Open Report command,
even though I have the code to trap Err 2501 (from many postings - all
looked the same to me) on the button the user pressed to get the
report.

I never see the code going to my error handling on the button. If I
debug, I am in an endless loop with the No data message, followed by
the 2501 message. I suspect my problem is somewhere else - maybe with
the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this error in it.
sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as Variable to print
Dim strStepErrorMsg As String ' Description for Error
Dim dtmDate As Date ' Date for File Name
Dim strWhere As String ' Where clause for PO reports
Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates string for
selection

' Find out what button was chosen, then print preview report for
that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & " And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
......(There are cases 3-6, but they are nearly identical to the others,
so I deleted the code here to save boring space. If it's needed, I'll
post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 - Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

....(Again, there is code for cases 3-6; virtually identical - just
setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, , "W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As Integer)
Exit Sub
End Sub

Sep 15 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
sara wrote:
I have a report that runs fine with data. If there is no data, I have
its NO Data event sending a MsgBox and cancelling the report.

Then it seems I still get the 2501 message on the Open Report command,
even though I have the code to trap Err 2501 (from many postings - all
looked the same to me) on the button the user pressed to get the
report.

I never see the code going to my error handling on the button. If I
debug, I am in an endless loop with the No data message, followed by
the 2501 message. I suspect my problem is somewhere else - maybe with
the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this error in it.
sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as Variable to print
Dim strStepErrorMsg As String ' Description for Error
Dim dtmDate As Date ' Date for File Name
Dim strWhere As String ' Where clause for PO reports
Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates string for
selection

' Find out what button was chosen, then print preview report for
that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & " And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical to the others,
so I deleted the code here to save boring space. If it's needed, I'll
post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 - Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually identical - just
setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, , "W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to "information"
Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in the above
procedure.

Also, I'm not a great fan of GoTos...especially when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't hurt either.
Sep 15 '06 #2

P: n/a
Thanks, Salad (I'm still working on the other db - but this is for
work)

I tried this - along with the spelling correction - and I still get the
same error. Any other ideas?

thanks
Sara
salad wrote:
sara wrote:
I have a report that runs fine with data. If there is no data, I have
its NO Data event sending a MsgBox and cancelling the report.

Then it seems I still get the 2501 message on the Open Report command,
even though I have the code to trap Err 2501 (from many postings - all
looked the same to me) on the button the user pressed to get the
report.

I never see the code going to my error handling on the button. If I
debug, I am in an endless loop with the No data message, followed by
the 2501 message. I suspect my problem is somewhere else - maybe with
the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this error in it.
sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as Variable to print
Dim strStepErrorMsg As String ' Description for Error
Dim dtmDate As Date ' Date for File Name
Dim strWhere As String ' Where clause for PO reports
Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates string for
selection

' Find out what button was chosen, then print preview report for
that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & " And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical to the others,
so I deleted the code here to save boring space. If it's needed, I'll
post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 - Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually identical - just
setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, , "W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As Integer)
Exit Sub
End Sub

Well, you could try this. Also, change the to "information"
Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in the above
procedure.

Also, I'm not a great fan of GoTos...especially when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't hurt either.
Sep 15 '06 #3

P: n/a
sara wrote:
Thanks, Salad (I'm still working on the other db - but this is for
work)

I tried this - along with the spelling correction - and I still get the
same error. Any other ideas?

thanks
Sara
'Here is a typical call to open a report from a form
Private Sub CommandReport_Click()
On Error GoTo Err_CommandReport

'open report, display data for ID = 1
DoCmd.OpenReport "ReportName", acPreview, , "[ID] = 1"

Exit_CommandReport:
Exit Sub

Err_CommandReport:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandReport
End Sub

*********************************

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to display", vbOKOnly, "No Data"
Cancel = True
End Sub

**********************************
'here is a typical OnOpen event I have in the report.
Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
Yours basically looks like mine. You have a bit more processing, but
close enough.

What I would do is enter STOP above a call to a report that has no
data...or click on the vertical bar where the call to open the report
occurs...and step thru the command execution. If you follow your logic,
you'll see it going to the error routine when you didn't expect it to.

I see no reason for your code to have any GoTo's...I see no benefit to
them. I'm trying to be delicate...you'll get pegged as a lightweight by
others.

I see no reason not to use an If/ElseIf in your code
If IsNull(StartDate) Then
...code
Elseif IsNull(EndDate) Then
...code
Else
...code
Endif

Stepping thru code will show you where your problem is. Get rid of
every reference to GoTo. In error routines, use Resume instead of GoTo.
salad wrote:
>>sara wrote:
>>>I have a report that runs fine with data. If there is no data, I have
its NO Data event sending a MsgBox and cancelling the report.

Then it seems I still get the 2501 message on the Open Report command,
even though I have the code to trap Err 2501 (from many postings - all
looked the same to me) on the button the user pressed to get the
report.

I never see the code going to my error handling on the button. If I
debug, I am in an endless loop with the No data message, followed by
the 2501 message. I suspect my problem is somewhere else - maybe with
the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this error in it.
sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as Variable to print
Dim strStepErrorMsg As String ' Description for Error
Dim dtmDate As Date ' Date for File Name
Dim strWhere As String ' Where clause for PO reports
Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates string for
selection

' Find out what button was chosen, then print preview report for
that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & " And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical to the others,
so I deleted the code here to save boring space. If it's needed, I'll
post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 - Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually identical - just
setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, , "W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As Integer)
Exit Sub
End Sub

Well, you could try this. Also, change the to "information"
Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in the above
procedure.

Also, I'm not a great fan of GoTos...especially when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't hurt either.

Sep 15 '06 #4

P: n/a
I'll certainly work on the GoTos and replace with Resume. I am "young"
enough to learn!~

I did step through the code (again - I'd done this before) and it's not
executing my error code at all. I get to the DoCmd.OpenReport, run the
OpenReport code (fine), then the NoData (get the message, "OK" it),
Execute the Cancel =True line, End Sub,
and immediately get the 2501 error, and the line that highlights is the
OpenReport line.

I have even put "On Error" immediately above the OpenReport line - I
still don't get my error code executed.

Could it have anything to do with using "Case"?

sara
salad wrote:
sara wrote:
Thanks, Salad (I'm still working on the other db - but this is for
work)

I tried this - along with the spelling correction - and I still get the
same error. Any other ideas?

thanks
Sara

'Here is a typical call to open a report from a form
Private Sub CommandReport_Click()
On Error GoTo Err_CommandReport

'open report, display data for ID = 1
DoCmd.OpenReport "ReportName", acPreview, , "[ID] = 1"

Exit_CommandReport:
Exit Sub

Err_CommandReport:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandReport
End Sub

*********************************

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to display", vbOKOnly, "No Data"
Cancel = True
End Sub

**********************************
'here is a typical OnOpen event I have in the report.
Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
Yours basically looks like mine. You have a bit more processing, but
close enough.

What I would do is enter STOP above a call to a report that has no
data...or click on the vertical bar where the call to open the report
occurs...and step thru the command execution. If you follow your logic,
you'll see it going to the error routine when you didn't expect it to.

I see no reason for your code to have any GoTo's...I see no benefit to
them. I'm trying to be delicate...you'll get pegged as a lightweight by
others.

I see no reason not to use an If/ElseIf in your code
If IsNull(StartDate) Then
...code
Elseif IsNull(EndDate) Then
...code
Else
...code
Endif

Stepping thru code will show you where your problem is. Get rid of
every reference to GoTo. In error routines, use Resume instead of GoTo.
salad wrote:
>sara wrote:

I have a report that runs fine with data. If there is no data, I have
its NO Data event sending a MsgBox and cancelling the report.

Then it seems I still get the 2501 message on the Open Report command,
even though I have the code to trap Err 2501 (from many postings - all
looked the same to me) on the button the user pressed to get the
report.

I never see the code going to my error handling on the button. If I
debug, I am in an endless loop with the No data message, followed by
the 2501 message. I suspect my problem is somewhere else - maybe with
the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this error in it.
sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as Variable to print
Dim strStepErrorMsg As String ' Description for Error
Dim dtmDate As Date ' Date for File Name
Dim strWhere As String ' Where clause for PO reports
Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates string for
selection

' Find out what button was chosen, then print preview report for
that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & " And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical to the others,
so I deleted the code here to save boring space. If it's needed, I'll
post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 - Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually identical - just
setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, , "W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to "information"
Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in the above
procedure.

Also, I'm not a great fan of GoTos...especially when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't hurt either.
Sep 16 '06 #5

P: n/a
"sara" <sa*******@yahoo.comwrote in
news:11*********************@h48g2000cwc.googlegro ups.com:
I'll certainly work on the GoTos and replace with Resume. I
am "young" enough to learn!~

I did step through the code (again - I'd done this before) and
it's not executing my error code at all. I get to the
DoCmd.OpenReport, run the OpenReport code (fine), then the
NoData (get the message, "OK" it), Execute the Cancel =True
line, End Sub, and immediately get the 2501 error, and the
line that highlights is the OpenReport line.

I have even put "On Error" immediately above the OpenReport
line - I still don't get my error code executed.

Could it have anything to do with using "Case"?

sara
Sara, open a code module and please check the setting of
Tools->options->general->Error Trapping

Anything except "Break on unhandled errors" might give you this
problem.
>
salad wrote:
>sara wrote:
Thanks, Salad (I'm still working on the other db - but this
is for work)

I tried this - along with the spelling correction - and I
still get the same error. Any other ideas?

thanks
Sara

'Here is a typical call to open a report from a form
Private Sub CommandReport_Click()
On Error GoTo Err_CommandReport

'open report, display data for ID = 1
DoCmd.OpenReport "ReportName", acPreview, , "[ID] = 1"

Exit_CommandReport:
Exit Sub

Err_CommandReport:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandReport
End Sub

*********************************

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to display", vbOKOnly, "No
Data" Cancel = True
End Sub

**********************************
'here is a typical OnOpen event I have in the report.
Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
Yours basically looks like mine. You have a bit more
processing, but close enough.

What I would do is enter STOP above a call to a report that
has no data...or click on the vertical bar where the call to
open the report occurs...and step thru the command execution.
If you follow your logic, you'll see it going to the error
routine when you didn't expect it to.

I see no reason for your code to have any GoTo's...I see no
benefit to them. I'm trying to be delicate...you'll get
pegged as a lightweight by others.

I see no reason not to use an If/ElseIf in your code
If IsNull(StartDate) Then
...code
Elseif IsNull(EndDate) Then
...code
Else
...code
Endif

Stepping thru code will show you where your problem is. Get
rid of every reference to GoTo. In error routines, use
Resume instead of GoTo.
salad wrote:

sara wrote:

I have a report that runs fine with data. If there is no
data, I have its NO Data event sending a MsgBox and
cancelling the report.

Then it seems I still get the 2501 message on the Open
Report command, even though I have the code to trap Err
2501 (from many postings - all looked the same to me) on
the button the user pressed to get the report.

I never see the code going to my error handling on the
button. If I debug, I am in an endless loop with the No
data message, followed by the 2501 message. I suspect my
problem is somewhere else - maybe with the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this
error in it. sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet
Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as
Variable to print Dim strStepErrorMsg As String
' Description for Error Dim dtmDate As Date
' Date for File Name
Dim strWhere As String ' Where clause
for PO reports Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates
string for selection

' Find out what button was chosen, then print preview
report for that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the
reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" &
dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & "
And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with
Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the
reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" &
dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with
Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical
to the others, so I deleted the code here to save boring
space. If it's needed, I'll post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following
informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 -
Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num,
nothing
strMerch =
Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually
identical - just setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err
Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, ,
"W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As
Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to
"information" Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following
informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in
the above procedure.

Also, I'm not a great fan of GoTos...especially when Resume
is normally used. For example, I'd do this instead or
using your GoTo. Err_Report_Open:
MsgBox "Call Sara with the following information: Err
Report Open" Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't
hurt either.



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 16 '06 #6

P: n/a
sara, just an idea (it's late and my mind is not at its sharpest), but is it
possible that the error is a database error rather than a vb error, and so
would be better trappable in the error event of the form or report?
-john

"sara" <sa*******@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
I'll certainly work on the GoTos and replace with Resume. I am "young"
enough to learn!~

I did step through the code (again - I'd done this before) and it's not
executing my error code at all. I get to the DoCmd.OpenReport, run the
OpenReport code (fine), then the NoData (get the message, "OK" it),
Execute the Cancel =True line, End Sub,
and immediately get the 2501 error, and the line that highlights is the
OpenReport line.

I have even put "On Error" immediately above the OpenReport line - I
still don't get my error code executed.

Could it have anything to do with using "Case"?

sara
salad wrote:
>sara wrote:
Thanks, Salad (I'm still working on the other db - but this is for
work)

I tried this - along with the spelling correction - and I still get the
same error. Any other ideas?

thanks
Sara

'Here is a typical call to open a report from a form
Private Sub CommandReport_Click()
On Error GoTo Err_CommandReport

'open report, display data for ID = 1
DoCmd.OpenReport "ReportName", acPreview, , "[ID] = 1"

Exit_CommandReport:
Exit Sub

Err_CommandReport:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandReport
End Sub

*********************************

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to display", vbOKOnly, "No Data"
Cancel = True
End Sub

**********************************
'here is a typical OnOpen event I have in the report.
Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
Yours basically looks like mine. You have a bit more processing, but
close enough.

What I would do is enter STOP above a call to a report that has no
data...or click on the vertical bar where the call to open the report
occurs...and step thru the command execution. If you follow your logic,
you'll see it going to the error routine when you didn't expect it to.

I see no reason for your code to have any GoTo's...I see no benefit to
them. I'm trying to be delicate...you'll get pegged as a lightweight by
others.

I see no reason not to use an If/ElseIf in your code
If IsNull(StartDate) Then
...code
Elseif IsNull(EndDate) Then
...code
Else
...code
Endif

Stepping thru code will show you where your problem is. Get rid of
every reference to GoTo. In error routines, use Resume instead of GoTo.
salad wrote:

sara wrote:

I have a report that runs fine with data. If there is no data, I have
its NO Data event sending a MsgBox and cancelling the report.

Then it seems I still get the 2501 message on the Open Report command,
even though I have the code to trap Err 2501 (from many postings - all
looked the same to me) on the button the user pressed to get the
report.

I never see the code going to my error handling on the button. If I
debug, I am in an endless loop with the No data message, followed by
the 2501 message. I suspect my problem is somewhere else - maybe with
the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this error in
it.
sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as Variable to print
Dim strStepErrorMsg As String ' Description for Error
Dim dtmDate As Date ' Date for File Name
Dim strWhere As String ' Where clause for PO reports
Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates string for
selection

' Find out what button was chosen, then print preview report for
that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a message to
enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to
enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & " And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a message to
enter
date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a message to
enter
date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" & dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with Ship date
Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical to the
others,
so I deleted the code here to save boring space. If it's needed, I'll
post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 - Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually identical - just
setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, , "W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to "information"
Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in the above
procedure.

Also, I'm not a great fan of GoTos...especially when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Open:
MsgBox "Call Sara with the following information: Err Report
Open"
Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't hurt either.


Sep 16 '06 #7

P: n/a
That's IT!! I finally learned to set break on all errors, and I forgot
to set it back. THANK YOU!!

I feel a combination or relieved and stupid - but mostly grateful!

sara
Bob Quintal wrote:
"sara" <sa*******@yahoo.comwrote in
news:11*********************@h48g2000cwc.googlegro ups.com:
I'll certainly work on the GoTos and replace with Resume. I
am "young" enough to learn!~

I did step through the code (again - I'd done this before) and
it's not executing my error code at all. I get to the
DoCmd.OpenReport, run the OpenReport code (fine), then the
NoData (get the message, "OK" it), Execute the Cancel =True
line, End Sub, and immediately get the 2501 error, and the
line that highlights is the OpenReport line.

I have even put "On Error" immediately above the OpenReport
line - I still don't get my error code executed.

Could it have anything to do with using "Case"?

sara
Sara, open a code module and please check the setting of
Tools->options->general->Error Trapping

Anything except "Break on unhandled errors" might give you this
problem.

salad wrote:
sara wrote:
Thanks, Salad (I'm still working on the other db - but this
is for work)

I tried this - along with the spelling correction - and I
still get the same error. Any other ideas?

thanks
Sara

'Here is a typical call to open a report from a form
Private Sub CommandReport_Click()
On Error GoTo Err_CommandReport

'open report, display data for ID = 1
DoCmd.OpenReport "ReportName", acPreview, , "[ID] = 1"

Exit_CommandReport:
Exit Sub

Err_CommandReport:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandReport
End Sub

*********************************

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to display", vbOKOnly, "No
Data" Cancel = True
End Sub

**********************************
'here is a typical OnOpen event I have in the report.
Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
Yours basically looks like mine. You have a bit more
processing, but close enough.

What I would do is enter STOP above a call to a report that
has no data...or click on the vertical bar where the call to
open the report occurs...and step thru the command execution.
If you follow your logic, you'll see it going to the error
routine when you didn't expect it to.

I see no reason for your code to have any GoTo's...I see no
benefit to them. I'm trying to be delicate...you'll get
pegged as a lightweight by others.

I see no reason not to use an If/ElseIf in your code
If IsNull(StartDate) Then
...code
Elseif IsNull(EndDate) Then
...code
Else
...code
Endif

Stepping thru code will show you where your problem is. Get
rid of every reference to GoTo. In error routines, use
Resume instead of GoTo.

salad wrote:

sara wrote:

I have a report that runs fine with data. If there is no
data, I have its NO Data event sending a MsgBox and
cancelling the report.

Then it seems I still get the 2501 message on the Open
Report command, even though I have the code to trap Err
2501 (from many postings - all looked the same to me) on
the button the user pressed to get the report.

I never see the code going to my error handling on the
button. If I debug, I am in an endless loop with the No
data message, followed by the 2501 message. I suspect my
problem is somewhere else - maybe with the error handling?

Can anyone help? This is VERY frustrating!

Code below.

Thanks so much. I can't release this to the user with this
error in it. sara

[The name of the button is cmdPOReports]

Private Sub cmdPOReports_Click()
On Error GoTo Err_cmdPOReports_Click

' The user has chosen the frame with all the Pallet
Reports

On Error GoTo Err_cmdPOReports_Click

Dim strDocName As String ' Report as
Variable to print Dim strStepErrorMsg As String
' Description for Error Dim dtmDate As Date
' Date for File Name
Dim strWhere As String ' Where clause
for PO reports Dim lngMerchantKey As Long
Dim lngDeptNum As Long
Dim strVendor As String

Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strBetween As String ' Between dates
string for selection

' Find out what button was chosen, then print preview
report for that choice

Select Case Me.fraPOReports

Case 1 ' POs for a Merchant - Range

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the
reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" &
dtmEndDate &
"#"

strWhere = " [SuggShipDate] " & strBetween

' If user selected "ALL", show ALL merchants in range

lngMerchantKey = Me.cboMerchant.Column(0)

If lngMerchantKey = 0 Then
strWhere = strWhere
Else
strWhere = "[MerchantKey] = " & lngMerchantKey & "
And " &
strWhere
End If
strDocName = "rptPODetails"

strStepErrorMsg = "Tell IT there was a problem with
Merchant POs"

DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click

Case 2 ' PO Ship Date Range

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtStartDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtEndDate) Then
MsgBox "Please enter the Ending Date for the
reports", ,
"W5-Enter Report Date"
Me.txtEndDate.SetFocus
GoTo Exit_cmdPOReports_Click

End If

dtmStartDate = Me.txtStartDate
dtmEndDate = Me.txtEndDate
strBetween = "Between #" & dtmStartDate & "# and #" &
dtmEndDate &
"#"

strDocName = "rptPODetails"

strWhere = " [SuggShipDate] " & strBetween

strStepErrorMsg = "Tell IT there was a problem with
Ship date Range
Rpt"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPOReports_Click
.....(There are cases 3-6, but they are nearly identical
to the others, so I deleted the code here to save boring
space. If it's needed, I'll post it)

End Select
Exit_cmdPOReports_Click:
Exit Sub

Err_cmdPOReports_Click:
If Err = 2501 Then
Else
MsgBox "Contact Sara with the following
informaiton " _
& Err.Nuumber & "" & Err.Description, , "W5 -
Print PO
Reports"
Resume Exit_cmdPOReports_Click
End If

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(Cancel As Integer)
'Tell the user there is no data

MsgBox "There are no POs for this criteria "

Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintReports.fraPOReports

Case 1
' Merchant Report Sort: Merch Last Name, PO Num,
nothing
strMerch =
Forms!frmPrintReports.cboMerchant.Column(1)

Me.GroupLevel(0).ControlSource = "MerchLastName"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

Case 2
' Sugg Ship Date Sort: Sugg Ship Date, PO Num, nothing

Me.GroupLevel(0).ControlSource = "SuggShipDate"
Me.GroupLevel(1).ControlSource = "PONum"
Me.GroupLevel(2).ControlSource = "=1"
GoTo Exit_Report_Open

...(Again, there is code for cases 3-6; virtually
identical - just setting the sort order on the report)

End Select
Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox "Call Sara with the following information: Err
Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description, ,
"W5 - Error
Report Open Code"
GoTo Exit_Report_Open

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(DataErr As Integer, Response As
Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to
"information" Err_cmdPOReports_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following
informaiton " _
& Err.Nuumber & "" & Err.Description, ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPOReports_Click

End Sub

You'll notice I moved the Resume out of the IF statement in
the above procedure.

Also, I'm not a great fan of GoTos...especially when Resume
is normally used. For example, I'd do this instead or
using your GoTo. Err_Report_Open:
MsgBox "Call Sara with the following information: Err
Report Open" Resume Exit_Report_Open
End Sub

This may not correct your problem, but it certainly won't
hurt either.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Sep 16 '06 #8

P: n/a
"sara" <sa*******@yahoo.comwrote in
news:11*********************@i42g2000cwa.googlegro ups.com:
That's IT!! I finally learned to set break on all errors, and
I forgot to set it back. THANK YOU!!
Been there, done that, more than once :-)
I feel a combination or relieved and stupid - but mostly
grateful!

sara
I'll take the relieved, and grateful. You are not stupid.
Forgetful, and possibly preoccupied.
Bob Quintal wrote:
>
Sara, open a code module and please check the setting of
Tools->options->general->Error Trapping

Anything except "Break on unhandled errors" might give you
this problem.
>

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 17 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.