473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VBA SQL Select stmt multiple rows found but not getting RecordCount > 1

Hi folks: Am doing a VBA SQL Select stmt with multiple rows found and
not getting RecordCount > 1. I've verified there are multiple rows
found by copying my SQL stmt from Debug window and pasting it to a
query - retrieves many rows. I need to program to handle many Rows in
VBA. Suggestions much appreciated!

Here is an excerpt of my VBA code after the SQLstmt is built:

Debug.Print SQLstmt
Set RecSet1 = SQLtbl.OpenRecordset(SQLstmt)
If (RecSet1.RecordCount > 1) Then ...

*NOTE: I posted this qstn yesterday and cannot find it.. Not sure
why, will try posting one more time :~|

- Don Fleming, Bellevue Wa.

Nov 13 '05 #1
4 4868

do*********@pse.com wrote:
Hi folks: Am doing a VBA SQL Select stmt with multiple rows found and
not getting RecordCount > 1. I've verified there are multiple rows
found by copying my SQL stmt from Debug window and pasting it to a
query - retrieves many rows. I need to program to handle many Rows in
VBA. Suggestions much appreciated!

Here is an excerpt of my VBA code after the SQLstmt is built:

Debug.Print SQLstmt
Set RecSet1 = SQLtbl.OpenRecordset(SQLstmt)
If (RecSet1.RecordCount > 1) Then ...

*NOTE: I posted this qstn yesterday and cannot find it.. Not sure
why, will try posting one more time :~|

- Don Fleming, Bellevue Wa.


After Set RecSet1...
RecSet1.MoveLast

This is a known and common problem.

James A. Fortune

Nov 13 '05 #2
do*********@pse.com wrote:
Debug.Print SQLstmt
Set RecSet1 = SQLtbl.OpenRecordset(SQLstmt)
If (RecSet1.RecordCount > 1) Then ...


Try the following to see if it helps:

Debug.Print SQLstmt
Set RecSet1 = SQLtbl.OpenRecordset(SQLstmt)
'Go to the end of the recordset and, if necessary, go back to the
'start. This will sewt recordcount to the number of records
RecSet.MoveLast
RecSet.MoveFirst
If (RecSet1.RecordCount > 1) Then ...

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #3
Yes, that does it allright! Big Thanks Tim!

I'll add it is too bad these stmts needed though, shouldn't have to,
but now that I know I'm off & running :~)

Nov 13 '05 #4
do*********@pse.com wrote in
news:11*********************@f14g2000cwb.googlegro ups.com:
Yes, that does it allright! Big Thanks Tim!

I'll add it is too bad these stmts needed though, shouldn't have
to, but now that I know I'm off & running :~)


The reason this happens is that Jet does not load the entire
recordset immediately, but only requests data pages as they are
needed. It cannot calculate an accurate recordcount until all the
data pages of the table have been retrieved. The MoveLast forces
that to happen.

However, don't think that .Recordcount is not accurate in some
respects. If it's anything other than 0 then you know that some
records have been returned, and if it's 0, you definitely know that
no records matched your criteria. If it's not 0, it may or may not
be accurate, something you can't know until you force it to update
with the .MoveLast.

In most cases, you don't need the recordcount, all you need to check
is if the .Recordcount is not 0.

If you are opening your recordset just to get a recordcount, then
it's more efficient to use Count(*) as your SQL (instead of
retrieving all the matching records and then doing a .MoveLast),
because Jet SQL is optimized to be more efficient with that than it
is with the .MoveLast.

The only case where using .MoveLast to get the accurate record count
is justified is if you need to retrieve the accurate recordcount at
the same time as you're doing something else in your recordset. In
my e, this happens a lot less often than you'd think it would.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5

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

Similar topics

2
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
10
by: AC Slater | last post by:
I have 1 table (out of many) that has very poor performance when performing a select into on. The select statement is called multiple times. We've found each call to take almost 1 second... we...
2
by: Andy S. | last post by:
Hi, I'm trying to declare and use temporary tables. I have written the following code in Java. Creating the tablespace (i can see the tablespace created using the Control Center), the temporary...
5
by: Silvio Matthes | last post by:
Hello, I'm new to the list and did not find a suitable answer to my question so here it is: I try to select the rows of a table where the content of a varchar-column is empty ('') and...
1
by: TechBoy | last post by:
In VB6 I have this code for returning data to a recordset via 2 Selects: 1. Select * from MyTable (98 rows of data are here) rs.recordcount returns "98" 2. Select count(*) from MyTable...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
19
by: hexagram | last post by:
Hi guys good day, can anybody help for my problem The Scenario is A Listbox (ID) - Multiple Select - everytime i choose in the list box the following outbound textbutton and subform will...
0
by: Jeff | last post by:
..NET 2.0 I'm working on a .NET 2.0 project which are using a DataSet for all communication with the database. Here is the problem: I want to search a table based on a matching criteria (I...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.