Results 1 to 10 of 10

Thread: [RESOLVED] Getting ODBC-linked RecordCount without using MoveLast

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Johannesburg, South Africa
    Posts
    92

    Resolved [RESOLVED] Getting ODBC-linked RecordCount without using MoveLast

    I'm opening an ODBC-linked recordset from an Access database. When it opens the recordset the RecordCount = 1. MoveLast obviously pulls the entire recordset over from the server into the database which resets RecordCount to the correct value. But is there a cleaner way of doing this? Are there any options that can be used in the OpenRecordset function that can do this when the recordset is opened?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Johannesburg, South Africa
    Posts
    92

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Sorry can a mod please move this thread to the Database Development forum. I realise it's in the wrong place.

  3. #3
    Member
    Join Date
    Jul 2008
    Posts
    41

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Generally, if you use either of:- Static or Dynamic Cursors then the actual recordcount will be returned.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Johannesburg, South Africa
    Posts
    92

    Re: Getting ODBC-linked RecordCount without using MoveLast

    I'm opening it as a snapshot and it's still only returning RecordCount = 1.

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Use an aggregate version of the query, e.g. COUNT, to have an idea how many records will be returned before executing query itself.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Johannesburg, South Africa
    Posts
    92

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Thanks for the suggestion, but that seems to be even less clean and more inefficient than using MoveLast.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Getting ODBC-linked RecordCount without using MoveLast

    The efficiency depends on several factors (usually in favour of a separate query), but it does take more code.

    While it is for ADO rather than DAO, you might find something useful in the article Why does Recordcount sometimes equal -1? from our Database Development FAQs/Tutorials (at the top of this forum)

    Quote Originally Posted by klempie
    Sorry can a mod please move this thread to the Database Development forum. I realise it's in the wrong place.
    Done.

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Quote Originally Posted by klempie
    Thanks for the suggestion, but that seems to be even less clean and more inefficient than using MoveLast.
    So your definition of efficiency has nothing to do with network usage ... Then why do you need recordcount in the first place?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Johannesburg, South Africa
    Posts
    92

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Quote Originally Posted by si_the_geek
    The efficiency depends on several factors (usually in favour of a separate query), but it does take more code.

    While it is for ADO rather than DAO, you might find something useful in the article Why does Recordcount sometimes equal -1? from our Database Development FAQs/Tutorials (at the top of this forum)

    Done.
    Thanks si. A useful link which I will bookmark for future use. Unfortunately JET returns 1 for RecordCount so it would appear that it only populates the recordset with the first record and you have to use a Move method to get the rest of them over. I don't know how the internals of JET work but that is what the behaviour is.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Johannesburg, South Africa
    Posts
    92

    Re: Getting ODBC-linked RecordCount without using MoveLast

    Quote Originally Posted by leinad31
    So your definition of efficiency has nothing to do with network usage ... Then why do you need recordcount in the first place?
    Leinad...sorry. Once again I have not expressed myself clearly enough.

    The code uses the recordset regardless of what the recordcount is BUT the value of RecordCount determines the execution path. It just seems to me that executing an aggregate statement as well as the query is a bit unnecessary, but I stand to be corrected.

    In any event I have sorted out the issue by writing a wrapper which looks something like

    Code:
    Public Function OpenRecordset(query as String, [Options]) As Recordset
    
       Dim rs as Recordset
       Set rs  = db.OpenRecordset(query, [Options])
       rs.MoveLast
       rs.MoveFirst
    
       OpenRecordset = rs
    End Function
    Not ideal but at least it only appears in the code once this way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width