473,598 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error-trapping question

I'm trying to improve my code so that when I open a recordset object,
I can absolutely guarantee it is closed and is set = Nothing. I have
read some old threads and they all say to use the functional
equivalent of the following code:

Public Sub CloseRecordset( )
On Error GoTo Sub_Error
Dim rs As Recordset

rs.FindFirst "This Will Error"

Sub_Exit:
On Error Resume Next
rs.Close '<----"Object variable or with block not set"
Set rs = Nothing

Sub_Error:
GoTo Sub_Exit
End Sub
However, *THIS CODE DOES NOT WORK*. It should attempt to "rs.Close"
and fail, and move to the next record as dictated by the "On Error
Resume Next" line. But it doesn't; it pops up the Debug/End/Help box
here (the default error handling).

I'm using Access 97, and yes, this is cut/pasted directly out of my
test function. I understand that originally, I have it go to
Sub_Error whenever an error occurs. When I get to the exit point (the
Sub_Exit label), it should switch to the "resume next" behavior, but
instead apparently resets the error trapping to default. What am I
doing wrong?
Pete
Nov 12 '05 #1
8 3364
Pete, you need to add the line:
Exit Sub
immediately after:
Set rs = Nothing.

If you do not exit sub at this point, the code falls into the error trapping
routine, and is sent back to the Sub_Exit label.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Pete" <ps********@zom bieworld.com> wrote in message
news:98******** *************** ***@posting.goo gle.com...
I'm trying to improve my code so that when I open a recordset object,
I can absolutely guarantee it is closed and is set = Nothing. I have
read some old threads and they all say to use the functional
equivalent of the following code:

Public Sub CloseRecordset( )
On Error GoTo Sub_Error
Dim rs As Recordset

rs.FindFirst "This Will Error"

Sub_Exit:
On Error Resume Next
rs.Close '<----"Object variable or with block not set"
Set rs = Nothing

Sub_Error:
GoTo Sub_Exit
End Sub
However, *THIS CODE DOES NOT WORK*. It should attempt to "rs.Close"
and fail, and move to the next record as dictated by the "On Error
Resume Next" line. But it doesn't; it pops up the Debug/End/Help box
here (the default error handling).

I'm using Access 97, and yes, this is cut/pasted directly out of my
test function. I understand that originally, I have it go to
Sub_Error whenever an error occurs. When I get to the exit point (the
Sub_Exit label), it should switch to the "resume next" behavior, but
instead apparently resets the error trapping to default. What am I
doing wrong?
Pete

Nov 12 '05 #2
step thru and tell us which line is crashing
Nov 12 '05 #3
Try:
Dim rs As DAO.Recordset

If that line generates an error, it is a references issue. Details:
http://allenbrowne.com/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"phappyman" <me*********@db forums.com> wrote in message
news:33******** ********@dbforu ms.com...

Thanks, but that isn't the problem. I built the test sub just to make
absolutely sure that what I was writing happened. The reason why I
forgot the "Exit Sub" line is because my subroutine *never got that
far*. Here is the (updated) subroutine:

Public Sub CloseRecordset( )

On Error GoTo Sub_Error

Dim rs As Recordset

rs.FindFirst "This Will Error"

Sub_Exit:

On Error Resume Next

rs.Close

Set rs = Nothing

Exit Sub

Sub_Error:

GoTo Sub_Exit

End Sub



The problem is the same as before, but the obvious (unrelated) error has
been fixed.

Pete

Original question:
> I'm trying to improve my code so that when I open a recordset object,

> I can absolutely guarantee it is closed and is set = Nothing. I have

> read some old threads and they all say to use the functional

> equivalent of the following code:

> Public Sub CloseRecordset( )

> On Error GoTo Sub_Error

> Dim rs As Recordset

> rs.FindFirst "This Will Error"

> Sub_Exit:

> On Error Resume Next

> rs.Close '<----"Object variable or with block not set"

> Set rs = Nothing

> Sub_Error:

> GoTo Sub_Exit

> End Sub

> However, *THIS CODE DOES NOT WORK*. It should attempt to "rs.Close"

> and fail, and move to the next record as dictated by the "On Error

> Resume Next" line. But it doesn't; it pops up the Debug/End/Help box

> here (the default error handling).

> I'm using Access 97, and yes, this is cut/pasted directly out of my

> test function. I understand that originally, I have it go to

> Sub_Error whenever an error occurs. When I get to the exit
> point (the

> Sub_Exit label), it should switch to the "resume next" behavior, but

> instead apparently resets the error trapping to default. What am I

> doing wrong?

> Pete

--
Posted via http://dbforums.com

Nov 12 '05 #4
Let me start over. This is not a references issue-the code runs. I
am using Access 97 and there isn't an ADO reference set, so the
ADODB/DAO precedence is not an issue.
I'm trying to improve my code so that when I open a recordset object,
I can absolutely guarantee it is closed and is set = Nothing. I have
read some old threads and they all say to use the functional
equivalent of the following code, which uses the "On Error Resume
Next" at the function's exit point:

'The numbers "01"-"12" at the beginning of the lines
'were added for readability
'Please note that my function does not have those
'numbers in the code, so no kneejerk replies please

01 Public Sub CloseRecordset( )
02 On Error GoTo Sub_Error
03 Dim rs As Recordset

04 rs.FindFirst "This Will Error"

05 Sub_Exit:
06 On Error Resume Next
07 rs.Close '<----"Object variable or with block not set"
'Above error message appears on previous
'line; it shouldn't

08 Set rs = Nothing

09 Exit Sub

10 Sub_Error:
11 GoTo Sub_Exit
12 End Sub
This is the question: why does the On Error Resume Next not work? I
have stepped through the code, and it goes 01-02-03-04-10-11-05-06-07
and then POPS UP the default Access error handling on line 07.
Remember that line 06 has just instructed the environment to "Resume
Next" on an error. WHY DOES "On Error Resume Next" FAIL TO WORK AS
ADVERTISED?

That is my question.
Pete
Nov 12 '05 #5
Between steps 03 and 04 you willneed to OPEN the recordset. You can't find
a record until the set is open
Nov 12 '05 #6
"hal boyles" <ha********@tim einc.com> wrote in message news:<bk******* ***@inntp-m1.news.aol.com >...
Between steps 03 and 04 you willneed to OPEN the recordset. You can't find
a record until the set is open


Thanks, but no thanks. The point is not that the function WORKS.
Because the function doesn't DO ANYTHING ANYWAY. So stop critiquing
the FAKE FUNCTION I WROTE TO PROVE A POINT.

I'm tired of people not reading my post. If I'm being unclear, sorry.
My problem was that the line "On Error Resume Next" does not work as
advertised. Read my other most recent post again.

Yes, I'm probably being too rude, but so far I'm 0 for 4 on replies.
Nov 12 '05 #7
"Pete" <ps********@zom bieworld.com> wrote in message
news:98******** *************** **@posting.goog le.com...
"hal boyles" <ha********@tim einc.com> wrote in message

news:<bk******* ***@inntp-m1.news.aol.com >...
Between steps 03 and 04 you willneed to OPEN the recordset. You can't find
a record until the set is open


Thanks, but no thanks. The point is not that the function WORKS.
Because the function doesn't DO ANYTHING ANYWAY. So stop critiquing
the FAKE FUNCTION I WROTE TO PROVE A POINT.

I'm tired of people not reading my post. If I'm being unclear, sorry.
My problem was that the line "On Error Resume Next" does not work as
advertised. Read my other most recent post again.

Yes, I'm probably being too rude, but so far I'm 0 for 4 on replies.


The only thing I notice that is different from how I usually do things is that I
would use...

10 Sub_Error:
11 Resume Sub_Exit
12 End Sub

....instead of GoTo Sub_Exit. I do exactly what your code example is attempting and I
do not get an error on the rs.Close line.
Nov 12 '05 #8
> The only thing I notice that is different from how I usually do things is that I
would use...

10 Sub_Error:
11 Resume Sub_Exit
12 End Sub

...instead of GoTo Sub_Exit. I do exactly what your code example is attempting and I
do not get an error on the rs.Close line.


Thanks! This was exactly my problem. I changed the "GoTo" to Resume
and it worked flawlessly.
Pete
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4366
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
2
2958
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to unexpected run-time problems. Exceptions on the other hand can not be simply ignored. In order to solve this error codes problem I suggest using error object instead of error codes. Each function has to return an error object that stores an error
7
4994
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying. I created the websetup and built the MSI, have the bundled version. Copied to webserver and ran Websetup.msi. Said I had to remove old version, which I did, then reran WebSetup.msi and keeps giving me this error. "The installer was interrupted...
3
16217
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very strange error. In your experience, where I should looking to find the real error? Surely the sintax of glut is correct... gcc.exe -c glut_bitmap.c -o glut_bitmap.o -I"C:/Dev-Cpp/include" -I"../../include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG...
0
12025
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in '/CinemaBookingSystem' Application. -------------------------------------------------------------------------------- ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process
1
3283
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly, but throws a load of linker errors
0
4733
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: Target CoreCompile: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Vbc.exe
2
5312
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
4
9053
by: jk2l | last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 11 error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 12 error LNK2001: unresolved external symbol __imp__glEnable@4 Model_3DS.obj ...
1
4153
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- Error: Unresolved external 'ImqMgr::~ImqMgr()' referenced from C:\DOCUMENTS AND SETTINGS\228753\MY DOCUMENTS\BORLAND STUDIO PROJECTS\DLLEXERCISE\DEBUG_BUILD\MANI.OBJ Error: Unresolved external 'ImqObj::~ImqObj()' referenced from C:\DOCUMENTS AND...
0
7987
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8264
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6718
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.