Results 1 to 6 of 6
  1. #1
    Stan Denman is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    50

    Counting Records in a table

    I need to count the records in a table programatically in a table. I have a table, "Verbs", and I have a form in which I have an unbound text box names text48. Table "Verbs" has 200 records. Table "verbs" is the datasource for a subform. I want filter what records in the subform gets displayed by the record number. Here is the code for a click event on form.

    Private Sub cmdVerb_Click()
    Dim db As Database


    Dim Upper As Integer


    Set db = CurrentDb
    Upper = db.OpenRecordset("Verbs").RecordCount
    Text48.Value = Upper


    End Sub

    The value I get in text48? 826. How in the world could this have happened with a table of 200 records?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    =DCount("*","verbs")
    as the Record Source property of Text48. BTW IMHO it would be better to rename the text box with something more meaningful like txtVerbTotal.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    think Bob means Controlsource for the textbox

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Yes. Thank you Ajax. That was indeed what I meant. Not only knowledgeable but psychic too 😆

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Not sure what was going on...as your original code should work fine...as will Bob's...but have to ask about what, exactly, you're planning to do here.

    Records in Access Tables do not actually have 'record numbers.' A Table is more like a bag full of marbles (to use a common comparison) moving around in no particular order.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    As Linq has suggested, it might be helpful to you and readers if you told us in simple terms what you trying to accomplish.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. counting records in parent table
    By bilalo in forum Reports
    Replies: 3
    Last Post: 05-24-2019, 05:58 PM
  2. Counting records, that have child records?
    By lithium in forum Access
    Replies: 4
    Last Post: 10-28-2015, 09:07 AM
  3. Counting records
    By frustratedwithaccess in forum Queries
    Replies: 4
    Last Post: 03-25-2015, 06:18 PM
  4. counting records
    By Jrw76 in forum Access
    Replies: 5
    Last Post: 01-14-2014, 02:11 PM
  5. Counting Only Certain Records
    By jtphenom in forum Queries
    Replies: 9
    Last Post: 03-29-2011, 01:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums