I have an access 2007 database and i have some code that runs a query, however depending on the search i get the RTE 3021 happening. i know the reason that this error occurs, being that there is no record in a query search that i do. i have started trying to resolve this problem by doing this: If rs.BOF = True Then Dim message message = MsgBox(““No Matches found.””, vbOKOnly, ““Error””) End If The only problem with this is that the code continues, i have searched the internet for a solution for this, but couldn’t find anything for it. i i just need some code that will stop it from runnig any futher if rs.BOF is true.

hi,

I quite understand what u mean in my own small way,.,
i want to c how i can profer solution to this…

can u try this:?
’ this code selects records from the database tables and stores them in a recordset called rs.

rs.open “select colunms from tablename where condition”,connectionname,adopenenumDynamic,adlocke numoptimistic

'this code checks whether recordset contains a particular record or not
if rs.fields(“columnname”).value <> textboxname.text then
msgbox (“Invalid record or record not found”)

'this code displays an error message when a recordlimit is reached.
public sub FirstRecord_click()
if rs.BOF=true then
msgbox (“Begining of Records. Press Next to continue.”)
else
rs.MoveFirst
endif

public sub NextRecord_click()
if rs.EOF=true then
msgbox (“End of Records. Press Next to continue.”)
else
rs.MoveNext
endif

public sub PreviousRecord_click()
if rs.BOF=true then
msgbox (“Begining of Records. Press Next to continue.”)
else
rs.MoveNext
endif

public sub LastRecord_click()
if rs.EOF=true then
msgbox (“End of Records. Press Next to continue.”)
else
rs.MoveNext
endif

Hope this helps
Thanks
Bye

Memory leaks are prevented/avoided.

John Warner

From: mgc92 via visualbasic-l [mailto:visualbasic-l@Groups.ITtoolbox.com]
Sent: Saturday, February 27, 2010 5:51 PM
To: john
Subject: RE:[visualbasic-l] Run time Error 3021 need to stop code from
running

Posted by mgc92
on Feb 27 at 6:18 PM

so by releasing that memory it will allow the program to run a little smother? im just guessing here…

It has to do with releasing the resources set aside in memory to handle
those objects.
It is considered “good housekeeping” and can help prevent those bugs that
nobody can explain.
It was probably more of a problem on older systems where available RAM was
precious.

Perhaps someone else can start another thread and explain this in more
detail.

Len Robichaud
IT Project Manager
lrobichaud@visualcomfort.com
713-686-5999 x4951

From: mgc92 via visualbasic-l [mailto:visualbasic-l@Groups.ITtoolbox.com]
Sent: Saturday, February 27, 2010 1:49 PM
To: LenRobichaud
Subject: RE:[visualbasic-l] Run time Error 3021 need to stop code from
running

Posted by mgc92
on Feb 27 at 2:49 PM

what is the purpose of closing it or unsetting it?

End Sub can only occur Once in your procedure but Exit Sub can be used
whenever you need to Escape.

Also, as a best practice when writing code, remember:
If you Open It. Close It. (rs.Close)
If you Set It. Un-Set It. (set rs = Nothing)

Len Robichaud
IT Project Manager
lrobichaud@visualcomfort.com
713-686-5999 x4951

From: mgc92 via visualbasic-l [mailto:visualbasic-l@Groups.ITtoolbox.com]
Sent: Saturday, February 27, 2010 12:01 PM
To: LenRobichaud
Subject: RE:[visualbasic-l] Run time Error 3021 need to stop code from
running

Posted by mgc92
on Feb 27 at 1:03 PM

problem soved, using exit sub, thank you Len.

ahh, thankyou, sorry that i did not mention that, but yes, i tried end sub before and that did not work, becase i stil had more code. I will try exit sub now :smiley:

why does access 2007 not suport this?

im not familiar with ado data controller. will have to look it up

You don’t say how you are calling this but you need to exit the sub (or
Function):
If rs.BOF = True Then
Dim message
message = MsgBox(“No Matches found.”, vbOKOnly, “Error”)

rs.Close
set rs = Nothing
Exit Sub (or Exit Function)

End If

Len Robichaud
IT Project Manager
lrobichaud@visualcomfort.com
713-686-5999 x4951

From: mgc92 via visualbasic-l [mailto:visualbasic-l@Groups.ITtoolbox.com]
Sent: Saturday, February 27, 2010 11:31 AM
To: LenRobichaud
Subject: [visualbasic-l] Run time Error 3021 need to stop code from running

Posted by mgc92
on Feb 27 at 12:33 PM

I have an access 2007 database and i have some code that runs a query,
however depending on the search i get the RTE 3021 happening.

i know the reason that this error occurs, being that there is no record in a
query search that i do. i have started trying to resolve this problem by
doing this:

If rs.BOF = True Then
Dim message
message = MsgBox(“No Matches found.”, vbOKOnly, “Error”)

End If

The only problem with this is that the code continues, i have searched the
internet for a solution for this, but couldn’t find anything for it. i

i just need some code that will stop it from runnig any futher if rs.BOF is
true.

first of all if u r using vb6 then ACS 07 will not support it, try to
convert the database file into 97 or
use vb 2008, or there is another solution use ado data controller it makes
the flexible search.

thank you