2501 error not going to error handler

  • Thread starter jln via AccessMonster.com
  • Start date
J

jln via AccessMonster.com

Here's my problem When i run into a report that has no data it cancels the
print job of the report. and when it does this i get the 2501 error. When i
step thought the code it never goes to the error handler when the error pops
up. This was working for 4 months or so and just stoped with no changes being
made. to the code.

Here is my button code.
Private Sub Command3_Click()

Dim strWhere As String
strWhere = "1=1"
If Not IsNull(Me.txtInvNo) Then
strWhere = strWhere & "And [Investor_Number]=" & Me.txtInvNo
End If

On Error GoTo Err_Command3_Click

DoCmd.OpenReport "Rec", acprint, , strWhere
DoCmd.OpenReport "ESCADV/CORPADV", acprint, , strWhere
DoCmd.OpenReport "MI_Claims", acprint, , strWhere
DoCmd.OpenReport "MI Refunds II", acprint, , strWhere
DoCmd.OpenReport "NEG/ESC/COPRADV/1", acprint, , strWhere
DoCmd.OpenReport "rpt_PPP", acprint, , strWhere
DoCmd.OpenReport "MI_Refunds", acprint, , strWhere
DoCmd.OpenReport "RECNEG", acprint, , strWhere
DoCmd.OpenReport "MIReinstatements", acprint, , strWhere
DoCmd.OpenReport "negPPP", acprint, , strWhere


Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
If Error.number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_Command3_Click
End If
End Sub

Here is my report code
MsgBox "There is no data for this report"
Cancel = True
 
S

Stefan Hoffmann

hi,
Here's my problem When i run into a report that has no data it cancels the
print job of the report. and when it does this i get the 2501 error. When i
step thought the code it never goes to the error handler when the error pops
up. This was working for 4 months or so and just stoped with no changes being
made. to the code.
I do not really understand your problem.
Here is my button code.
Private Sub Command3_Click()

Dim strWhere As String
strWhere = "1=1"
But here is a space missing, cause you don't add it in the If-clause.
If Not IsNull(Me.txtInvNo) Then
strWhere = strWhere & "And [Investor_Number]=" & Me.txtInvNo
End If
The rest of your code seems to be okay.

In the No Data event i also call

DoCmd.CancelEvent


mfG
--> stefan <--
 
J

jln via AccessMonster.com

What is going on is when a report has no data it will give me the msgbox
saying no data then I hit ok and then pops the 2501 error. IT never goes to
the error handler. So im not catching the error thats what i need to fix.

Stefan said:
hi,
Here's my problem When i run into a report that has no data it cancels the
print job of the report. and when it does this i get the 2501 error. When i
step thought the code it never goes to the error handler when the error pops
up. This was working for 4 months or so and just stoped with no changes being
made. to the code.
I do not really understand your problem.
Here is my button code.
Private Sub Command3_Click()

Dim strWhere As String
strWhere = "1=1"
But here is a space missing, cause you don't add it in the If-clause.
If Not IsNull(Me.txtInvNo) Then
strWhere = strWhere & "And [Investor_Number]=" & Me.txtInvNo
End If
The rest of your code seems to be okay.

In the No Data event i also call

DoCmd.CancelEvent

mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
What is going on is when a report has no data it will give me the msgbox
saying no data then I hit ok and then pops the 2501 error. IT never goes to
the error handler. So im not catching the error thats what i need to fix.
Tested this one?


mfG
--> stefan <--
 
K

Keith Wilby

jln via AccessMonster.com said:
Not that i have seen

So why is it in your code? As to your main problem, have you stepped
through the code line by line at run time to see where the pointer goes?
The code seems fine to me as is.

Keith.
 
S

Stefan Hoffmann

hi Keith,

Keith said:
So why is it in your code?
It's not necessary in his code.

When you initialize strWhere with a condition that is true then you can
append any further condition with AND or OR.

It's

--
strWhere = ""

If checkBox1.Value Then
If Len(strWhere) = 0 Then
strWhere = "condition1 "
Else
strWhere = strWhere & "condition1 "
End If
End If

If checkBox2.Value Then
If Len(strWhere) = 0 Then
strWhere = "condition2 "
Else
strWhere = strWhere & "condition2 "
End If
End If
--

vs.

--
strWhere = "1=1 "

If checkBox1.Value Then
strWhere = strWhere & "condition1 "
End If

If checkBox2.Value Then
strWhere = strWhere & "condition2 "
End If
--

The spaces at the end of the conditions are necessary.


mfG
--> stefan <--
 
S

Stefan Hoffmann

hi Keith,

Keith said:
I don't think that's the problem, I use Cancel = True and it works just
fine.
In some circumstances it throws an exception "The event was canceled.".
The .CancleEvent handles this.


mfG
--> stefan <--
 
D

Dirk Goldgar

jln via AccessMonster.com said:
Here's my problem When i run into a report that has no data it
cancels the print job of the report. and when it does this i get the
2501 error. When i step thought the code it never goes to the error
handler when the error pops up. This was working for 4 months or so
and just stoped with no changes being made. to the code.

In the VB Editor environment, click Tools -> Options..., go to the
General tab, and check the setting for Error Trapping. It should
probably be set to Break on Unhandled Errors. Is it?
 
J

jln via AccessMonster.com

You have it thats what it was. They upgrade access and thats when it started.
 

Ask a Question

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

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

Ask a Question

Top