Results 1 to 4 of 4

Thread: Record Count

  1. #1
    Join Date
    Apr 2004
    Location
    United Kingdom
    Posts
    56

    Question Unanswered: Record Count

    Hello there people,

    I am trying to set up a couple of fields that will count the number of records on a form. (This together with some custom navigation buttons will help the users here see things a little clearer when they are moving between records).

    I have used the code below and there are 5 records in total, but when the form is first opened the field [navRecNo] contains "1" and the field [navRecCount] contains "1". It's only when you go to the next record, or go to add a new record that the [navRecCount] actually contains the true number of total records, i.e. 5.

    Am I missing something here??

    Rusty

    =========================================
    Private Sub Form_Current()

    Me.navRecNo = Form.CurrentRecord
    Me.navRecCount = Form.RecordsetClone.RecordCount + IIf(Form.NewRecord, 1, 0) & " "

    End Sub

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    To get the recordcount for the form, you need to put the recordsetclone in a DAO recordset.

    Dim rstRcdCnt AS DAO.RECORDSET
    SET rstRcdCnt = Me.RecordsetClone
    rstClone.MoveLast
    Me.navRecCount=rstRcdCnt.RecordCount
    Inspiration Through Fermentation

  3. #3
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    This is normal behavior for some types of cursors.

    If you absolutly need a correct RecordCount do this

    rs.open
    if not (rs.bof and rs.eof)

    rs.movelast
    rs.movefirst

    end if

    But keep in mind if you have a huge recordset this will degrade performance somewhat.

    If the Recordset object supports approximate positioning or bookmarks—that is, Supports (adApproxPosition) or Supports (adBookmark), respectively, return True—this value will be the exact number of records in the Recordset regardless of whether it has been fully populated. If the Recordset object does not support approximate positioning, this property may be a significant drain on resources because all records will have to be retrieved and counted to return an accurate RecordCount value.

    The cursor type of the Recordset object affects whether the number of records can be determined. The RecordCount property will return -1 for a forward-only cursor, the actual count for a static or keyset cursor, and either -1 or the actual count, depending on the data source, for a dynamic cursor.
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  4. #4
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    I do this a fair bit because often I have the nagigation buttons/arrows removed.

    Pick a field where there is an entry for every record, perhaps an ID number you use or a surname field etc.

    Put an unbound text box on the form and for its data source

    =Count([NameNumber])

    Mike

Posting Permissions

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