One "Resume Next" or two?

Suppose I have error handling code similar to the following:

Err_MyFunction:
     on error resume next
     rst1.close
     rst2.close

I don't want to see an error message from trying to close recordset vars 
which are already closed. I actually want/expect them to be closed. But of 
course, depending on where the error occurred, one or both rst vars might 
still be open when the error handler fires, so I put the "resume next" 
statement to guard against this eventuality.

But suppose both rst vars are already closed when the error handler fires? 
In this case, both close statements should generate an error. Does the one 
"resume next" cover this? Do I need two "resume next" statements?


0
David
3/5/2008 1:14:21 AM
access 16762 articles. 3 followers. Follow

2 Replies
245 Views

Similar Articles

[PageSpeed] 54

You only need one Resume Next statement.

What that statement says is for every error that occurs from that point on, 
just continue on to the next line.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"David Portwood" <Mondrogan@yahoo.com> wrote in message 
news:47cdf3eb$0$16686$4c368faf@roadrunner.com...
> Suppose I have error handling code similar to the following:
>
> Err_MyFunction:
>     on error resume next
>     rst1.close
>     rst2.close
>
> I don't want to see an error message from trying to close recordset vars 
> which are already closed. I actually want/expect them to be closed. But of 
> course, depending on where the error occurred, one or both rst vars might 
> still be open when the error handler fires, so I put the "resume next" 
> statement to guard against this eventuality.
>
> But suppose both rst vars are already closed when the error handler fires? 
> In this case, both close statements should generate an error. Does the one 
> "resume next" cover this? Do I need two "resume next" statements?
>
> 


0
Douglas
3/5/2008 1:21:02 AM
I understand. Thanks, Doug.

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
news:eZFxz8lfIHA.5624@TK2MSFTNGP02.phx.gbl...
> You only need one Resume Next statement.
>
> What that statement says is for every error that occurs from that point 
> on, just continue on to the next line.
>
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "David Portwood" <Mondrogan@yahoo.com> wrote in message 
> news:47cdf3eb$0$16686$4c368faf@roadrunner.com...
>> Suppose I have error handling code similar to the following:
>>
>> Err_MyFunction:
>>     on error resume next
>>     rst1.close
>>     rst2.close
>>
>> I don't want to see an error message from trying to close recordset vars 
>> which are already closed. I actually want/expect them to be closed. But 
>> of course, depending on where the error occurred, one or both rst vars 
>> might still be open when the error handler fires, so I put the "resume 
>> next" statement to guard against this eventuality.
>>
>> But suppose both rst vars are already closed when the error handler 
>> fires? In this case, both close statements should generate an error. Does 
>> the one "resume next" cover this? Do I need two "resume next" statements?
>>
>>
>
> 


0
David
3/6/2008 2:25:35 PM
Reply:

Similar Artilces:

On error resume next not working
the following code is supposed to print sheet2 if there is a sheet two, then delete sheet2. So the first part checks if there is content on sheet2("A1") and prints it. If ther is no content on sheet2 the error handler skips this step. Then it is supposed to delete sheet2. If there is no sheet2 the error handler resume next is supposed to skip this part but it is not. If there is no sheet2 the line-Worksheets("Sheet2").Delete, returns a runtime error 9. Why does the on error resume next not working? Thanks Sub print() On Error GoTo skipprint If Not ...

On Error Resume Next not working
Access 2003, SP2. I've recently started having probems with several of my VBA routines not working properly. I've got some in-line error checking in a couple of places in an Access application and an Excel Macro. In one instance, I use the following code to allow a Cancel if there is no data for the report, but I get a "2501 OpenReport action was cancelled" error message on the OpenReport line of code. On Error Resume Next DoCmd.OpenReport "rpt_Circular_References", acViewPreview If Err.Number = 2501 then msgbox "No data to display in report" E...

Find Worksheet Name without On Error Resume Next
Is there a way to ensure a worksheet is in a workbook without using the On Error Resume Next statement? I have the name of the worksheet, now I want to search the workbook for that sheet, how do I do that? -- Cheers, Ryan Hi Ryan It can be done like this: Dim IsThere As Boolean TargetSh = "Sheet1" For Each sh In ThisWorkbook.Sheets If sh.Name = TargetSh Then IsThere = True Exit For End If Next If IsThere Then MsgBox ("Is in the workbook") Else MsgBox ("Is not in the workbook") End If Regards, Per ...

On error resume next problem
I have some code which looks something like this On error Resume Next Kill "C:\a.xls" Kill "C:\b.xls" Kill "C:\c.xls" Kill "C:\d.xls" Kill "C:\e.xls" On error goto 0 It works ok, but if the file doesn't exist the macro breaks and I ge an error message. Shouldn't the instruction, On error Resume Next prevent this problem? Thanks for any explanation Cheers fre -- freekril ----------------------------------------------------------------------- freekrill's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=756...

on Error goto 0 &on error resume next
Hi, In my macro,before I access the objects,i wrote "on error resume next" to trap any error that might occur.My questions are: 1) do I need to write somewhere in my code "on Error goto 0", to disable the error handeler.since with or without using "on error goto 0" in my macro,I do not see any differences. 2) is that enough to use "on error resume next" only once at the begining of my codes when I want to access the objects,or should I keep reaping it.since with or without using "on error resume next" in my macro,I do not see any difference. ...

On Error Resume Next
Hello everybody! I was wondering if someone could help me with the following. I wrote a macro which get's information with matches the criteria k from a Pivot Table. I've named K allready. Though it only returns "(Blank)" the criteria I stated in case K was not found. I tested it with criterias which were sure to have results but did not get any reslults other than (blank) either. I think it has got something to do with the "On Error Resume Next" I used but cant figure out what. Application.CommandBars("PivotTable").Visible = False On Error Resume...

One "Resume Next" or two?
Suppose I have error handling code similar to the following: Err_MyFunction: on error resume next rst1.close rst2.close I don't want to see an error message from trying to close recordset vars which are already closed. I actually want/expect them to be closed. But of course, depending on where the error occurred, one or both rst vars might still be open when the error handler fires, so I put the "resume next" statement to guard against this eventuality. But suppose both rst vars are already closed when the error handler fires? In this case, both close state...