VBA Table Record Count

Discussion in 'Microsoft Access' started by Guest, Jan 26, 2005.

  1. Guest

    Guest Guest

    Is there an easy way to count the records in a table without opening the
    table and counting each record some sort of a listfile function the gives you
    a count ???, any help would be appreciated.
     
    Guest, Jan 26, 2005
    #1
    1. Advertisements

  2. Guest

    Lynn Trapp Guest

    Create a saved query that pulls all the records from your table and then
    call the following function.

    Public Function GetRecordCount()
    Dim rst As DAO.Recordset
    Dim lngCount As Long

    Set rst = CurrentDb.OpenRecordset("YourQuery")

    With rst
    .MoveFirst
    .MoveLast
    lngCount = .RecordCount
    End With

    Debug.Print "Number of Records = " & lngCount

    End Function

    --
    Lynn Trapp
    MS Access MVP
    www.ltcomputerdesigns.com
    Access Security: www.ltcomputerdesigns.com/Security.htm


    "David Widener" <> wrote in message
    news:...
    > Is there an easy way to count the records in a table without opening the
    > table and counting each record some sort of a listfile function the gives
    > you
    > a count ???, any help would be appreciated.
    >
    >
     
    Lynn Trapp, Jan 26, 2005
    #2
    1. Advertisements

  3. Guest

    Andi Mayer Guest

    On Wed, 26 Jan 2005 06:39:02 -0800, "David Widener"
    <> wrote:

    >Is there an easy way to count the records in a table without opening the
    >table and counting each record some sort of a listfile function the gives you
    >a count ???, any help would be appreciated.
    >


    currentdb.TableDefs("myTablename").RecordCount

    ---
    If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
    MW
     
    Andi Mayer, Jan 26, 2005
    #3
  4. Guest

    Rick Brandt Guest

    Andi Mayer wrote:
    > On Wed, 26 Jan 2005 06:39:02 -0800, "David Widener"
    > <> wrote:
    >
    >> Is there an easy way to count the records in a table without opening
    >> the table and counting each record some sort of a listfile function
    >> the gives you a count ???, any help would be appreciated.
    >>

    >
    > currentdb.TableDefs("myTablename").RecordCount


    The above only works against a local Jet table. A linked table of any kind
    will just return -1.


    --
    I don't check the Email account attached
    to this message. Send instead to...
    RBrandt at Hunter dot com
     
    Rick Brandt, Jan 26, 2005
    #4
  5. Guest

    Guest Guest

    Thanks Andi that's exactly what I needed

    "Andi Mayer" wrote:

    > On Wed, 26 Jan 2005 06:39:02 -0800, "David Widener"
    > <> wrote:
    >
    > >Is there an easy way to count the records in a table without opening the
    > >table and counting each record some sort of a listfile function the gives you
    > >a count ???, any help would be appreciated.
    > >

    >
    > currentdb.TableDefs("myTablename").RecordCount
    >
    > ---
    > If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
    > MW
    >
     
    Guest, Jan 26, 2005
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ## Benjamin Adnam ##

    vba: howto select a record like klicking on record selector

    ## Benjamin Adnam ##, Oct 4, 2003, in forum: Microsoft Access
    Replies:
    2
    Views:
    1,960
    ## Benjamin Adnam ##
    Oct 5, 2003
  2. smeghead

    Updating Record Count into Table

    smeghead, Dec 12, 2004, in forum: Microsoft Access
    Replies:
    2
    Views:
    944
    smeghead
    Dec 12, 2004
  3. Fred Dagg

    record from table based on record from other table

    Fred Dagg, Jun 25, 2007, in forum: Microsoft Access
    Replies:
    1
    Views:
    184
    Ofer Cohen
    Jun 25, 2007
  4. John
    Replies:
    5
    Views:
    217
  5. spreadsheetlady
    Replies:
    1
    Views:
    943
    Jeff Boyce
    Jan 26, 2010
Loading...

Share This Page