[AccessD] MoveFirst needed in DAO?

Gustav Brock gustav at cactus.dk
Wed Aug 8 11:08:02 CDT 2012


Hi Dan and Charlotte

In my experience, the first record is the current after the recordset is created, thus doing a MoveFirst has no effect.

If no records exists, you can verify that in two ways:

  If rst.RecordCount = 0

or:

  If rst.BOF = True And rst.EOF = True

If just one record exists, I see:

  rst.BOF = False
  rst.EOF = False

leaving room to do either MovePrevious or MoveNext and that's all.

/gustav


>>> df.waters at comcast.net 08-08-12 16:41 >>>
I've always seen that in a newly opened DAO recordset, the recordset is
always positioned at the first record - IF THERE ARE ANY RECORDS!

So for most recordsets a check to see if any records exist is needed.

Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
Sent: Wednesday, August 08, 2012 9:17 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] MoveFirst needed in DAO?

In DAO, the newly opened recordset is positioned at BOF but not necessarily
on a record, IIRC.

Charlotte

On Wed, Aug 8, 2012 at 2:09 AM, Gustav Brock <gustav at cactus.dk> wrote:

> Hi all
>
> Having opened a DAO recordset:
>
>     Set rst = dbs.OpenRecordset(strSQL)
>
> often the first code line following is:
>
>     rst.MoveFirst
>
> or, if the recordset can be empty:
>
>     If rst.RecordCount > 0 Then
>       rst.MoveFirst
>     EndIf
>
> But is that really necessary? At which record could the recordset 
> possibly be positioned if not at the first?
>
> Even a snapshot or an ODBC linked recordset will not - as far as I 
> know - move anywhere until you tell it to do so.
>
> For ADO recordsets it is different as the recordcount can be -1 until 
> you, for example, have done a MoveLast.
>
> /gustav



More information about the AccessD mailing list