473,856 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tried Solutions from Post - Problem Error 2501 still exists

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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_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_cmdPORepor ts_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

End Select
Exit_Report_Ope n:
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_Ope n

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

Sep 15 '06 #1
8 2460
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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_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_cmdPORepor ts_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

End Select
Exit_Report_Ope n:
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_Ope n

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(Da taErr As Integer, Response As Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to "informatio n"
Err_cmdPOReport s_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly 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_Ope n
End Sub

This may not correct your problem, but it certainly won't hurt either.
Sep 15 '06 #2
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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_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_cmdPORepor ts_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

End Select
Exit_Report_Ope n:
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_Ope n

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

Well, you could try this. Also, change the to "informatio n"
Err_cmdPOReport s_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly 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_Ope n
End Sub

This may not correct your problem, but it certainly won't hurt either.
Sep 15 '06 #3
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_C lick()
On Error GoTo Err_CommandRepo rt

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

Exit_CommandRep ort:
Exit Sub

Err_CommandRepo rt:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandRep ort
End Sub

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

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(C ancel 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(Can cel 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(StartDat e) 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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_Click
.....(Ther e 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_cmdPORe ports_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

...(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_O pen:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description , , "W5 - Error
Report Open Code"
GoTo Exit_Report_Ope n

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

Well, you could try this. Also, change the to "informatio n"
Err_cmdPORepo rts_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Op en:
MsgBox "Call Sara with the following information: Err Report Open"
Resume Exit_Report_Ope n
End Sub

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

Sep 15 '06 #4
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.OpenRepor t, 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_C lick()
On Error GoTo Err_CommandRepo rt

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

Exit_CommandRep ort:
Exit Sub

Err_CommandRepo rt:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandRep ort
End Sub

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

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(C ancel 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(Can cel 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(StartDat e) 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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a message to enter
date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_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_cmdPORep orts_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

End Select
Exit_Report_O pen:
Exit Sub

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

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(Da taErr As Integer, Response As Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to "informatio n"
Err_cmdPORepor ts_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Ope n:
MsgBox "Call Sara with the following information: Err Report Open"
Resume Exit_Report_Ope n
End Sub

This may not correct your problem, but it certainly won't hurt either.
Sep 16 '06 #5
"sara" <sa*******@yaho o.comwrote in
news:11******** *************@h 48g2000cwc.goog legroups.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.OpenRepor t, 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_C lick()
On Error GoTo Err_CommandRepo rt

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

Exit_CommandRe port:
Exit Sub

Err_CommandRep ort:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandRep ort
End Sub

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

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(C ancel 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(Can cel 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(StartDat e) 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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the
reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_Click
.....(Ther e 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_cmdPORe ports_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num,
nothing
strMerch =
Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

...(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_O pen:
MsgBox "Call Sara with the following information: Err
Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description , ,
"W5 - Error
Report Open Code"
GoTo Exit_Report_Ope n

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(Da taErr As Integer, Response As
Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to
"informatio n" Err_cmdPOReport s_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following
informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly 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_Ope n
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
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*******@yaho o.comwrote in message
news:11******** *************@h 48g2000cwc.goog legroups.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.OpenRepor t, 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_C lick()
On Error GoTo Err_CommandRepo rt

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

Exit_CommandRe port:
Exit Sub

Err_CommandRep ort:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandRep ort
End Sub

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

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(C ancel 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(Can cel 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(StartDat e) 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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a message to
enter
date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_Click
.....(Ther e 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_cmdPORe ports_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num, nothing
strMerch = Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

...(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_O pen:
MsgBox "Call Sara with the following information: Err Report Open"
_
& vbCrLf & Err.Number & " " & Err.Description , , "W5 - Error
Report Open Code"
GoTo Exit_Report_Ope n

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(Da taErr As Integer, Response As Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to "informatio n"
Err_cmdPORepo rts_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly when Resume is normally
used. For example, I'd do this instead or using your GoTo.
Err_Report_Op en:
MsgBox "Call Sara with the following information: Err Report
Open"
Resume Exit_Report_Ope n
End Sub

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


Sep 16 '06 #7
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*******@yaho o.comwrote in
news:11******** *************@h 48g2000cwc.goog legroups.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.OpenRepor t, 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_C lick()
On Error GoTo Err_CommandRepo rt

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

Exit_CommandRep ort:
Exit Sub

Err_CommandRepo rt:
If Err.Number <2501 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume Exit_CommandRep ort
End Sub

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

'here is a typical NoData event I have in the report.
Private Sub Report_NoData(C ancel 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(Can cel 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(StartDat e) 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_Cl ick()
On Error GoTo Err_cmdPOReport s_Click

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

On Error GoTo Err_cmdPOReport s_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

' Check to see if the date is entered; if not, send a
message to enter date
If IsNull(Me.txtEn dDate) Then
MsgBox "Please enter the Ending Date for the
reports", ,
"W5-Enter Report Date"
Me.txtEndDate.S etFocus
GoTo Exit_cmdPORepor ts_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 = "rptPODetai ls"

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

DoCmd.OpenRepor t strDocName, acPreview, , strWhere
DoCmd.Maximize

GoTo Exit_cmdPORepor ts_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.txtSt artDate) Then
MsgBox "Please enter the Starting Date for the
reports", ,
"W5-Enter Report Date"
Me.txtStartDate .SetFocus
GoTo Exit_cmdPORepor ts_Click

End If

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

End If

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

strDocName = "rptPODetai ls"

strWhere = " [SuggShipDate] " & strBetween

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

GoTo Exit_cmdPORepor ts_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_cmdPORep orts_Click:
Exit Sub

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

End Sub

[In rptPODetails] NO data and On Open

Private Sub Report_NoData(C ancel 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(Can cel As Integer)
On Error GoTo Err_Report_Open

' Set Sorting and Grouping for this report

Dim strMerch As String
Select Case Forms.frmPrintR eports.fraPORep orts

Case 1
' Merchant Report Sort: Merch Last Name, PO Num,
nothing
strMerch =
Forms!frmPrintR eports.cboMerch ant.Column(1)

Me.GroupLevel(0 ).ControlSource = "MerchLastN ame"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

Me.GroupLevel(0 ).ControlSource = "SuggShipDa te"
Me.GroupLevel(1 ).ControlSource = "PONum"
Me.GroupLevel(2 ).ControlSource = "=1"
GoTo Exit_Report_Ope n

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

End Select
Exit_Report_O pen:
Exit Sub

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

End Sub
I even tried (based on a posting I saw):
Private Sub Report_Error(Da taErr As Integer, Response As
Integer)
Exit Sub
End Sub
Well, you could try this. Also, change the to
"information " Err_cmdPOReport s_Click:
If Err <2501 Then
MsgBox "Contact Sara with the following
informaiton " _
& Err.Nuumber & "" & Err.Description , ,_
"W5 - Print PO Reports"
End If
Resume Exit_cmdPORepor ts_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...especia lly 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_Ope n
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
"sara" <sa*******@yaho o.comwrote in
news:11******** *************@i 42g2000cwa.goog legroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8461
by: ColinWard | last post by:
My previous message was blank so Im trying again. I have a button on a form which opens the Import dialogue box. This works fine except if I click on the "X" to close the form I get Run-Time Error 2501: the DoMenuItem was Cancelled". How can I trap this error so that it doesn't display but simply closes the form? Thanks Colin
1
5611
by: Bob Dydd | last post by:
Hi everyone It's me again. I have an access 2000 database with 12 landscape reports which sometimes have to be FAXED and other times printed, so I have written the following code and put it in a module to bring up the print dialog: Public Function PrintAccess()
5
28975
by: fearblanco | last post by:
Hello - I am receiving the below error message when attempting to open a report. This database is used by approximately 20 users and only one user is having this problem (even I can't duplicate this error on my own PC). The command being used is DoCmd.OpenReport "rptSYS_ChangeInARDaily", acViewPreview OR DoCmd.OpenReport "rptSYS_ChangeInARDaily", acViewPreview, , "Collector=
3
6139
by: Ed Robichaud | last post by:
I'm temporarily stumped on how to handle/suppress an error (2501) if a user cancels sending an email. I'm using DoCmd.SendObject to trigger an Outlook send window, which works OK, but if the msg is cancelled (not sent) then a VB runtime error msg appears (#2501) that I would like to either hide or deal with. -Ed
4
9458
by: Keith | last post by:
I have the following code in the On No Data event of a report: **** On Error GoTo err_trap MsgBox "No items matching criteria.", vbInformation, gcApplication Cancel = True err_trap: If Err.Number = 2501 Then Exit Sub
2
3190
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
33
3173
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise it returns false. **I am not looking for comments on the usefulness of this function - it is only to demonstrate error handling** There are three versions of this code. David Fenton says under the earlier thread "DAO...
7
2959
by: Keith Wilby | last post by:
In an old A97 app I trap for error 2501 in a report's calling code just in case there are no records to return (set cancel = True in the report's No Data event). This doesn't seem to work in my A2k3 version of the same app. I know I'm missing something simple here but my brain's gone home already. Anyone help? Thanks - Keith.
0
1420
by: AccessAl | last post by:
Sorry for asking but I could not find any response and can only loop thru 25 pages every so often. I know this has been asked multiple times, but I cannot seem to find an answer that I haven 't used. I use this type of coding when no data exists for a report, but on occasion, My error trapping does not work. I can see no rhyme or reason why it wouldn't. MY CODE INSIDE THE REPORT MODULE IS: Private Sub Report_NoData(Cancel As Integer)...
0
9763
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10699
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10787
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9534
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7932
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7098
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4578
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4176
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.