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 8 2434
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.
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.
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.
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.
"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
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.
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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
| |