473,799 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error Handling For A Recordset

Tom
What is the code for a recordset in error handling code when the error may
or may not occur before the recordset was created? I tried the code below
but get the message:
Compile Error
Invalid Use Of Object
and Nothing is highlighted when I click debug.

If RstSurveySectio n <> Nothing Then
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
End If

Thanks!

Tom
Nov 13 '05 #1
6 5055

"Tom" <no***@email.co m> wrote in message
news:_J******** **********@news read3.news.atl. earthlink.net.. .
What is the code for a recordset in error handling code when the error may
or may not occur before the recordset was created? I tried the code below
but get the message:
Compile Error
Invalid Use Of Object
and Nothing is highlighted when I click debug.

If RstSurveySectio n <> Nothing Then
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
End If

Thanks!

Tom


If Not RstSurveySectio n Is Nothing Then
....
Nov 13 '05 #2
Should it be NULL instead of Nothing? just a guess here

Nov 13 '05 #3
Tom
"If Not RstSurveySectio n Is Nothing Then"
worked fine!

Tom
"Tom" <no***@email.co m> wrote in message
news:_J******** **********@news read3.news.atl. earthlink.net.. .
What is the code for a recordset in error handling code when the error may
or may not occur before the recordset was created? I tried the code below
but get the message:
Compile Error
Invalid Use Of Object
and Nothing is highlighted when I click debug.

If RstSurveySectio n <> Nothing Then
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
End If

Thanks!

Tom

Nov 13 '05 #4
Tom wrote:
"If Not RstSurveySectio n Is Nothing Then"
worked fine!


You still need to error trap, consider this

Set RstSurveySectio n = db.openrecordse t....
....some code
RstSurveySectio n.close
.... some code
if not RstSurveySectio n is nothing then
RstSurveySectio n.close ' <<<< Error will occur here
set RstSurveySectio n=nothing
end if

RstSurveySectio n can be closed or become invalid even if you don't
explicitly close it yourself, VBA isn't perfect or invunerable to cosmic
rays :-)

--
[OO=00=OO]
Nov 13 '05 #5
"Trevor Best" <no****@besty.o rg.uk> wrote in message
news:42******** **************@ news.zen.co.uk. ..
Tom wrote:
"If Not RstSurveySectio n Is Nothing Then"
worked fine!


You still need to error trap, consider this

Set RstSurveySectio n = db.openrecordse t....
...some code
RstSurveySectio n.close
... some code
if not RstSurveySectio n is nothing then
RstSurveySectio n.close ' <<<< Error will occur here
set RstSurveySectio n=nothing
end if

RstSurveySectio n can be closed or become invalid even if you don't
explicitly close it yourself, VBA isn't perfect or invunerable to cosmic
rays :-)

--
[OO=00=OO]

Indeed, so you might have it as part of your 'exit block' like:

Exit_MySub:

On Error Resume Next

If Not RstSurveySectio n Is Nothing Then
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
End If

Exit Sub
However, if you have the above error handling, it is doubtful whether it is
even worth checking if the object is nothing or not. In other words, you
might as well have:

Exit_MySub:
On Error Resume Next
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
Exit Sub
Having said that, I tend to write code as in the first example - it just
means that my coding always looks recognisable.


Nov 13 '05 #6
Justin Hoffman wrote:
Indeed, so you might have it as part of your 'exit block' like:

Exit_MySub:

On Error Resume Next

If Not RstSurveySectio n Is Nothing Then
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
End If

Exit Sub
However, if you have the above error handling, it is doubtful whether it is
even worth checking if the object is nothing or not. In other words, you
might as well have:

Exit_MySub:
On Error Resume Next
RstSurveySectio n.Close
Set RstSurveySectio n = Nothing
Exit Sub
Having said that, I tend to write code as in the first example - it just
means that my coding always looks recognisable.


I do like the second, I see no point in checking and preventing a
possible error if you're going to ignore it anyway.

--
[OO=00=OO]
Nov 13 '05 #7

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

Similar topics

8
3708
by: Niraj Khandwala | last post by:
Dear all, this error handling has been a pain since so manya days using ASP 3.0 with IIS 5.0 on W2K server Created a custom error page using the Server.GetLastError() and works fine in most of the cases. Following are the issues : 1. Have a hughe file (5-6 mb approx) to upload, now if there are any errors during upload i want to immediately throw an error and roll back the transaction.
8
3378
by: Pete | last post by:
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"
8
4068
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
2
3031
by: Steve Jorgensen | last post by:
When writing VB or VBA code that works with databases or other external libraries that cannot be trusted to automatically do the right thing when references to their objects are arbitrarily released, some thought must be put into how to make sure the objects will all be closed and released in the correct order, even in the result of an error. This requirement can make our code really ugly, even following the best of commonly known best...
3
6903
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records from rsSource into rsDest - if it finds a key violation then it deletes the current record from rsDest and adds the new record from rsSource. This works perfectly - but only for the first found duplicate record, it brings up the error
10
605
by: David | last post by:
Hello I am trying to collect errors and record them in a table instead of a popup message stopping my code. It seems to work ok, but when I try to add ERR.Description to my code it fails on Syntax Error (missing operator). Any help would be very much appreciated Thanks Dave Dim strSql As String strSql = "INSERT INTO tbllogoftimedevents(Log)VALUES('" &
33
3167
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise it returns false. **I am not looking for comments on the usefulness of this function - it is only to demonstrate error handling** There are three versions of this code. David Fenton says under the earlier thread "DAO...
10
2297
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise it returns false. **I am not looking for comments on the usefulness of this function - it is
9
3300
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error appears it, in 99%, of the cases, works if we just press the play button in VBA debug. Therefor we have maked an error handling which just tryes again. However, as this error handling is difficult to test because of maybe 1 or 2 errors a day, we...
0
9688
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
9544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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
10030
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...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.