VBA – On Error Resume Next

  • Thread starter Programmer - wannaB
  • Start date
P

Programmer - wannaB

Someone could please tell me why I need “On Error Resume Next†in this code.
I tried for hours to find the right line to set the filter of these
sus-reports, and kept getting different error messages, then I looked at the
form properties and noticed that the filter was what I was looking for and it
was getting set by the code, even though it would error out. Is there better
code I should be using or is this just one of those things????

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
If Year(Me.rFP10!FHDate) < Year(Now()) Then
Me.rFP11.Report.FilterOn = True
Me.rFP11.Report.Filter = "year(FHDate)=(Year(Now()) -2)"
Me.rFP12.Report.FilterOn = True
Me.rFP12.Report.Filter = "year(FHDate)=(Year(Now()) -3)"
Me.rFP13.Report.FilterOn = True
Me.rFP13.Report.Filter = "year(FHDate)=(Year(Now()) -4)"
Me.rFP14.Report.FilterOn = True
Me.rFP14.Report.Filter = "year(FHDate)=(Year(Now()) -5)"
End If
End Sub
 
A

Arvin Meyer [MVP]

On Error Resume Next

tells your code to ignore the error and go to the next line of code. It is
poor programming practice unless the errors are meaningless or you are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line before
the error and step through the code (F8) to find the error and fix it.
 
W

WANNABE

Thanks Arvin, but I understand that part, and I do use F8 to step through the
code.
Allow me to rephrase my question; When I step through the code I get an error
message
Run-time error '2101':
The setting you entered isn't valid for this property.
[Continue] [End] [Debug] [Help]
Yet when I use On Error Resume Next, the code works and does what I want. So
Does this
mean anything? How can I get the same affect that can be run with code that
doesn't need
resume next??? What code will provide the same results as what I have written
below
without any errors???
===========================
On Error Resume Next

tells your code to ignore the error and go to the next line of code. It is
poor programming practice unless the errors are meaningless or you are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line before
the error and step through the code (F8) to find the error and fix it.
 
A

Arvin Meyer [MVP]

I'm going to take a guess and say that you cannot changed the filter
property in the On Print event, that you'll need to do it in the On Format
event. When you step though the code, which line(s) throws the error?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

WANNABE said:
Thanks Arvin, but I understand that part, and I do use F8 to step through
the
code.
Allow me to rephrase my question; When I step through the code I get an
error
message
Run-time error '2101':
The setting you entered isn't valid for this property.
[Continue] [End] [Debug] [Help]
Yet when I use On Error Resume Next, the code works and does what I want.
So
Does this
mean anything? How can I get the same affect that can be run with code
that
doesn't need
resume next??? What code will provide the same results as what I have
written
below
without any errors???
===========================
On Error Resume Next

tells your code to ignore the error and go to the next line of code. It is
poor programming practice unless the errors are meaningless or you are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line
before
the error and step through the code (F8) to find the error and fix it.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

in
message news:[email protected]...
Someone could please tell me why I need "On Error Resume Next" in this
code.
I tried for hours to find the right line to set the filter of these
sus-reports, and kept getting different error messages, then I looked at
the
form properties and noticed that the filter was what I was looking for
and
it
was getting set by the code, even though it would error out. Is there
better
code I should be using or is this just one of those things????

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
If Year(Me.rFP10!FHDate) < Year(Now()) Then
Me.rFP11.Report.FilterOn = True
Me.rFP11.Report.Filter = "year(FHDate)=(Year(Now()) -2)"
Me.rFP12.Report.FilterOn = True
Me.rFP12.Report.Filter = "year(FHDate)=(Year(Now()) -3)"
Me.rFP13.Report.FilterOn = True
Me.rFP13.Report.Filter = "year(FHDate)=(Year(Now()) -4)"
Me.rFP14.Report.FilterOn = True
Me.rFP14.Report.Filter = "year(FHDate)=(Year(Now()) -5)"
End If
End Sub
 
P

Programmer - wannaB

I have tried this in other sections, but Detail section seemed to make the
most sense to me as that is the section that this data changes in.
The error occurs on each of the lines after IF. There is no error on the IF
line, so it recognizes the sub-report and the FHDate field on that
sub-report. I have also found that although it seems to work when I use "On
Error Resume Next" and I step through the code, It does not work consistantly
when I run the report with the VB window closed, and no breakpoints. I have
also found some issues regarding runtime error 2101 on the MSDN web site, but
I don't make any connection between wha tis documented there and this. Any
other suggestions would be greatly appreciated..
============================
Arvin Meyer said:
I'm going to take a guess and say that you cannot changed the filter
property in the On Print event, that you'll need to do it in the On Format
event. When you step though the code, which line(s) throws the error?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

WANNABE said:
Thanks Arvin, but I understand that part, and I do use F8 to step through
the
code.
Allow me to rephrase my question; When I step through the code I get an
error
message
Run-time error '2101':
The setting you entered isn't valid for this property.
[Continue] [End] [Debug] [Help]
Yet when I use On Error Resume Next, the code works and does what I want.
So
Does this
mean anything? How can I get the same affect that can be run with code
that
doesn't need
resume next??? What code will provide the same results as what I have
written
below
without any errors???
===========================
On Error Resume Next

tells your code to ignore the error and go to the next line of code. It is
poor programming practice unless the errors are meaningless or you are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line
before
the error and step through the code (F8) to find the error and fix it.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

in
message news:[email protected]...
Someone could please tell me why I need "On Error Resume Next" in this
code.
I tried for hours to find the right line to set the filter of these
sus-reports, and kept getting different error messages, then I looked at
the
form properties and noticed that the filter was what I was looking for
and
it
was getting set by the code, even though it would error out. Is there
better
code I should be using or is this just one of those things????

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
If Year(Me.rFP10!FHDate) < Year(Now()) Then
Me.rFP11.Report.FilterOn = True
Me.rFP11.Report.Filter = "year(FHDate)=(Year(Now()) -2)"
Me.rFP12.Report.FilterOn = True
Me.rFP12.Report.Filter = "year(FHDate)=(Year(Now()) -3)"
Me.rFP13.Report.FilterOn = True
Me.rFP13.Report.Filter = "year(FHDate)=(Year(Now()) -4)"
Me.rFP14.Report.FilterOn = True
Me.rFP14.Report.Filter = "year(FHDate)=(Year(Now()) -5)"
End If
End Sub
 
A

Arvin Meyer [MVP]

The Detail section is probably the correct one, but you are trying to change
something in the On Print event that should probably be done in the On
Format event.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Programmer - wannaB said:
I have tried this in other sections, but Detail section seemed to make the
most sense to me as that is the section that this data changes in.
The error occurs on each of the lines after IF. There is no error on the
IF
line, so it recognizes the sub-report and the FHDate field on that
sub-report. I have also found that although it seems to work when I use
"On
Error Resume Next" and I step through the code, It does not work
consistantly
when I run the report with the VB window closed, and no breakpoints. I
have
also found some issues regarding runtime error 2101 on the MSDN web site,
but
I don't make any connection between wha tis documented there and this.
Any
other suggestions would be greatly appreciated..
============================
Arvin Meyer said:
I'm going to take a guess and say that you cannot changed the filter
property in the On Print event, that you'll need to do it in the On
Format
event. When you step though the code, which line(s) throws the error?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

WANNABE said:
Thanks Arvin, but I understand that part, and I do use F8 to step
through
the
code.
Allow me to rephrase my question; When I step through the code I get
an
error
message
Run-time error '2101':
The setting you entered isn't valid for this property.
[Continue] [End] [Debug] [Help]
Yet when I use On Error Resume Next, the code works and does what I
want.
So
Does this
mean anything? How can I get the same affect that can be run with
code
that
doesn't need
resume next??? What code will provide the same results as what I have
written
below
without any errors???
===========================
On Error Resume Next

tells your code to ignore the error and go to the next line of code. It
is
poor programming practice unless the errors are meaningless or you are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line
before
the error and step through the code (F8) to find the error and fix it.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Programmer - wannaB" <[email protected]>
wrote
in
message Someone could please tell me why I need "On Error Resume Next" in this
code.
I tried for hours to find the right line to set the filter of these
sus-reports, and kept getting different error messages, then I looked
at
the
form properties and noticed that the filter was what I was looking for
and
it
was getting set by the code, even though it would error out. Is there
better
code I should be using or is this just one of those things????

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
If Year(Me.rFP10!FHDate) < Year(Now()) Then
Me.rFP11.Report.FilterOn = True
Me.rFP11.Report.Filter = "year(FHDate)=(Year(Now()) -2)"
Me.rFP12.Report.FilterOn = True
Me.rFP12.Report.Filter = "year(FHDate)=(Year(Now()) -3)"
Me.rFP13.Report.FilterOn = True
Me.rFP13.Report.Filter = "year(FHDate)=(Year(Now()) -4)"
Me.rFP14.Report.FilterOn = True
Me.rFP14.Report.Filter = "year(FHDate)=(Year(Now()) -5)"
End If
End Sub
 
P

Programmer - wannaB

I tried this in the On Format event as well and I get the same error.
It may be that changing the filter of a sub-report is not possible, and if I
needed to rewrite this as a crosstab query >> can you provide some references
for a simplton? Something a first grader would understand.
=============================
Arvin Meyer said:
The Detail section is probably the correct one, but you are trying to change
something in the On Print event that should probably be done in the On
Format event.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Programmer - wannaB said:
I have tried this in other sections, but Detail section seemed to make the
most sense to me as that is the section that this data changes in.
The error occurs on each of the lines after IF. There is no error on the
IF
line, so it recognizes the sub-report and the FHDate field on that
sub-report. I have also found that although it seems to work when I use
"On
Error Resume Next" and I step through the code, It does not work
consistantly
when I run the report with the VB window closed, and no breakpoints. I
have
also found some issues regarding runtime error 2101 on the MSDN web site,
but
I don't make any connection between wha tis documented there and this.
Any
other suggestions would be greatly appreciated..
============================
Arvin Meyer said:
I'm going to take a guess and say that you cannot changed the filter
property in the On Print event, that you'll need to do it in the On
Format
event. When you step though the code, which line(s) throws the error?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"WANNABE" <SameAsB4> wrote in message
Thanks Arvin, but I understand that part, and I do use F8 to step
through
the
code.
Allow me to rephrase my question; When I step through the code I get
an
error
message
Run-time error '2101':
The setting you entered isn't valid for this property.
[Continue] [End] [Debug] [Help]
Yet when I use On Error Resume Next, the code works and does what I
want.
So
Does this
mean anything? How can I get the same affect that can be run with
code
that
doesn't need
resume next??? What code will provide the same results as what I have
written
below
without any errors???
===========================
On Error Resume Next

tells your code to ignore the error and go to the next line of code. It
is
poor programming practice unless the errors are meaningless or you are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line
before
the error and step through the code (F8) to find the error and fix it.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Programmer - wannaB" <[email protected]>
wrote
in
message Someone could please tell me why I need "On Error Resume Next" in this
code.
I tried for hours to find the right line to set the filter of these
sus-reports, and kept getting different error messages, then I looked
at
the
form properties and noticed that the filter was what I was looking for
and
it
was getting set by the code, even though it would error out. Is there
better
code I should be using or is this just one of those things????

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
If Year(Me.rFP10!FHDate) < Year(Now()) Then
Me.rFP11.Report.FilterOn = True
Me.rFP11.Report.Filter = "year(FHDate)=(Year(Now()) -2)"
Me.rFP12.Report.FilterOn = True
Me.rFP12.Report.Filter = "year(FHDate)=(Year(Now()) -3)"
Me.rFP13.Report.FilterOn = True
Me.rFP13.Report.Filter = "year(FHDate)=(Year(Now()) -4)"
Me.rFP14.Report.FilterOn = True
Me.rFP14.Report.Filter = "year(FHDate)=(Year(Now()) -5)"
End If
End Sub
 
A

Arvin Meyer [MVP]

The easiest reference is the Crosstab query wizard.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Programmer - wannaB said:
I tried this in the On Format event as well and I get the same error.
It may be that changing the filter of a sub-report is not possible, and if
I
needed to rewrite this as a crosstab query >> can you provide some
references
for a simplton? Something a first grader would understand.
=============================
Arvin Meyer said:
The Detail section is probably the correct one, but you are trying to
change
something in the On Print event that should probably be done in the On
Format event.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

in
message news:[email protected]...
I have tried this in other sections, but Detail section seemed to make
the
most sense to me as that is the section that this data changes in.
The error occurs on each of the lines after IF. There is no error on
the
IF
line, so it recognizes the sub-report and the FHDate field on that
sub-report. I have also found that although it seems to work when I
use
"On
Error Resume Next" and I step through the code, It does not work
consistantly
when I run the report with the VB window closed, and no breakpoints. I
have
also found some issues regarding runtime error 2101 on the MSDN web
site,
but
I don't make any connection between wha tis documented there and this.
Any
other suggestions would be greatly appreciated..
============================
:

I'm going to take a guess and say that you cannot changed the filter
property in the On Print event, that you'll need to do it in the On
Format
event. When you step though the code, which line(s) throws the error?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"WANNABE" <SameAsB4> wrote in message
Thanks Arvin, but I understand that part, and I do use F8 to step
through
the
code.
Allow me to rephrase my question; When I step through the code I
get
an
error
message
Run-time error '2101':
The setting you entered isn't valid for this property.
[Continue] [End] [Debug] [Help]
Yet when I use On Error Resume Next, the code works and does what I
want.
So
Does this
mean anything? How can I get the same affect that can be run with
code
that
doesn't need
resume next??? What code will provide the same results as what I
have
written
below
without any errors???
===========================
On Error Resume Next

tells your code to ignore the error and go to the next line of code.
It
is
poor programming practice unless the errors are meaningless or you
are
running the code in a loop or query where it could stop hundreds or
thousands of times without something to let it go on.

If you are getting errors, it's best to set a breakpoint at the line
before
the error and step through the code (F8) to find the error and fix
it.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Programmer - wannaB" <[email protected]>
wrote
in
message Someone could please tell me why I need "On Error Resume Next" in
this
code.
I tried for hours to find the right line to set the filter of these
sus-reports, and kept getting different error messages, then I
looked
at
the
form properties and noticed that the filter was what I was looking
for
and
it
was getting set by the code, even though it would error out. Is
there
better
code I should be using or is this just one of those things????

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
If Year(Me.rFP10!FHDate) < Year(Now()) Then
Me.rFP11.Report.FilterOn = True
Me.rFP11.Report.Filter = "year(FHDate)=(Year(Now()) -2)"
Me.rFP12.Report.FilterOn = True
Me.rFP12.Report.Filter = "year(FHDate)=(Year(Now()) -3)"
Me.rFP13.Report.FilterOn = True
Me.rFP13.Report.Filter = "year(FHDate)=(Year(Now()) -4)"
Me.rFP14.Report.FilterOn = True
Me.rFP14.Report.Filter = "year(FHDate)=(Year(Now()) -5)"
End If
End Sub
 

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

Similar Threads

VBA - report filter 1
VBA code for my report 5
VBA - What am I doing wrong? 8
Yes or No Prompt 11
BeforeUpdate Problem 7
HELP NEEDED WITH REPORT 1
Error 3314 2
Why I get Error 2105 5

Top