dbTalk Databases Forums  

determine if recordset is empty BEFORE running movefirst

comp.databases.ms-access comp.databases.ms-access


Discuss determine if recordset is empty BEFORE running movefirst in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MLH
 
Posts: n/a

Default determine if recordset is empty BEFORE running movefirst - 03-07-2008 , 06:20 AM






160 Dim DB As Database, Rst As Recordset, QD As QueryDef
170 Set DB = CurrentDb()
180 Set QD = DB.CreateQueryDef("", MySQL)
190 Set Rst = QD.OpenRecordset(dbOpenDynaset)
HOW TO COUNT RECORDS IN Rst BEFORE NEXT LINE?
200 Rst.MoveFirst


Reply With Quote
  #2  
Old   
Rick Brandt
 
Posts: n/a

Default Re: determine if recordset is empty BEFORE running movefirst - 03-07-2008 , 06:39 AM






MLH wrote:
Quote:
160 Dim DB As Database, Rst As Recordset, QD As QueryDef
170 Set DB = CurrentDb()
180 Set QD = DB.CreateQueryDef("", MySQL)
190 Set Rst = QD.OpenRecordset(dbOpenDynaset)
HOW TO COUNT RECORDS IN Rst BEFORE NEXT LINE?
200 Rst.MoveFirst
Either...

If Not Rst.EOF Then...

Or

If Rst.RecordCount > 0 Then...

Note that upon opening a Recordset the RecordCount cannot be trusted for an
accurate total count until you do a MoveLast, but it CAN be trusted to
indicate whether there are zero records or (something more than zero).

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com




Reply With Quote
  #3  
Old   
MLH
 
Posts: n/a

Default Re: determine if recordset is empty BEFORE running movefirst - 03-07-2008 , 08:23 AM



Thanks, Rick.
I had actually tried .count and it did not
compile (of course). Dunno why I didn't
just check the HELP before posting.
I appreciate it.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


On Fri, 7 Mar 2008 06:39:58 -0600, "Rick Brandt"
<rickbrandt2 (AT) hotmail (DOT) com> wrote:

Quote:
MLH wrote:
160 Dim DB As Database, Rst As Recordset, QD As QueryDef
170 Set DB = CurrentDb()
180 Set QD = DB.CreateQueryDef("", MySQL)
190 Set Rst = QD.OpenRecordset(dbOpenDynaset)
HOW TO COUNT RECORDS IN Rst BEFORE NEXT LINE?
200 Rst.MoveFirst

Either...

If Not Rst.EOF Then...

Or

If Rst.RecordCount > 0 Then...

Note that upon opening a Recordset the RecordCount cannot be trusted for an
accurate total count until you do a MoveLast, but it CAN be trusted to
indicate whether there are zero records or (something more than zero).


Reply With Quote
  #4  
Old   
DFS
 
Posts: n/a

Default Re: determine if recordset is empty BEFORE running movefirst - 03-07-2008 , 10:54 PM



Rick Brandt wrote:

Quote:
Note that upon opening a Recordset the RecordCount cannot be trusted
for an accurate total count until you do a MoveLast, but it CAN be
trusted to indicate whether there are zero records or (something more
than zero).
Is that true for DISTINCT queries as well? I seem to remember doing some
tests and it always returned the correct recordcount w/o MoveLast.





Reply With Quote
  #5  
Old   
Rick Brandt
 
Posts: n/a

Default Re: determine if recordset is empty BEFORE running movefirst - 03-08-2008 , 05:52 AM



DFS wrote:
Quote:
Rick Brandt wrote:

Note that upon opening a Recordset the RecordCount cannot be trusted
for an accurate total count until you do a MoveLast, but it CAN be
trusted to indicate whether there are zero records or (something more
than zero).

Is that true for DISTINCT queries as well? I seem to remember doing
some tests and it always returned the correct recordcount w/o
MoveLast.
I didn't mean to imply that it would always be incorrect without a MoveLast,
just that it often is. For it to be "trusted" it would beed to be correct
100% of the time and it clearly does not meet that standard.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com




Reply With Quote
  #6  
Old   
lyle fairfield
 
Posts: n/a

Default Re: determine if recordset is empty BEFORE running movefirst - 03-08-2008 , 06:40 AM



"DFS" <nospam (AT) dfs_ (DOT) com> wrote in
news_oAj.1514$vr3.627 (AT) bignews2 (DOT) bellsouth.net:

Quote:
Rick Brandt wrote:

Note that upon opening a Recordset the RecordCount cannot be trusted
for an accurate total count until you do a MoveLast, but it CAN be
trusted to indicate whether there are zero records or (something more
than zero).alted perhaps

Is that true for DISTINCT queries as well? I seem to remember doing
some tests and it always returned the correct recordcount w/o
MoveLast.
I think that's correct. I am guessing that JET uses or creates a unique
index to do a Select Distinct and that the recordset inherits the index's
DistinctCount property. (Debug.Print DBEngine(0)(0).TableDefs
("Employees").Indexes("LastName").DistinctCount )

Table type recordsets return the correct recordcount on opening.

ADO Recordsets are a different kettle of fish, of course.

--
lyle fairfield


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.