Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling

Status
Not open for further replies.

Igwiz

Technical User
Jun 3, 2003
88
0
0
CA
Hi,

I've run into a problem with my error handling. I didn;t realise that using the On Error Goto line statement actually instigated an error handling routine that rendered future error trapping useless. I was using it as a way to jump say three lines of code and carry on execution

eg

On Error Goto jump
-Error occurs- (1)
.
.
.
jump:
On Error Goto jump1
-Error occurs- (2)
.
.
.
jump1:

But the code hits a fatal error at (2) because it thinks it is in an error handling routine. How do I just jump some lines of code when an error occurs? In the above example, it as a PivotSelect command that sometimes fails because the resulting pivot table is empty and I need to then skip all the copying statements.

Any help would be appreciated.
Thanks,

Ig


 
use
On Error Goto 0
to reset the error handling until the next On Error....

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
I've done that already and no joy!
 
that's how on error goto 0 works....
This is an example:

On error goto jump
'code
'code

jump:
'code
on error goto 0
'code
'code
'code
on error goto jump1
'code
'code
jump1:

etc etc

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
I know which is why I am baffled! Here is the part of code not working:

On Error GoTo jump
ActiveSheet.PivotTables("PT).PivotSelect _
"I[ALL]", xlDataAndLabel

Selection.Copy Destination:=Workbooks("x.xls").Sheets("DS").Range("R1")

jump:

On Error GoTo 0

ActiveSheet.PivotTables("PT").PivotFields("AC").CurrentPage = "a"

ActiveSheet.PivotTables("PT").PivotFields("AS").CurrentPage = "(blank)"

On Error GoTo jump1

ActiveSheet.PivotTables("PT").PivotSelect _
"I[ALL]", xlLabelOnly

****IT BOMBS OUT AT THE ABOVE LINE BECAUSE THE TABLE IS EMPTY WITH A RUNTIME 1004 ERROR****
.
.
.
jump1:

Very Baffled!
 
hmmm - very baffled also - your code should work in theory

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
It is definitely the first On Error that is messing it up cuz if I disable that, the second On Error works as expected. I am now puling my hair out!
 
CRACKED IT! Inside the code I call another routine and that was triggering the Error routine. Sorry for wasting your time!
 
no worries - glad you got it resolved

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top