Results 1 to 7 of 7
  1. #1
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69

    Can I Create a Form Control that Displays the Amount of Records?

    At the bottom of my forms and tables, there is a status bar that indicates the total number of records in that particular form/table.
    Just out of curiosity…is there a way to create a control inside a form, that displays the total record number?


    For example, here's a screen shot sample of the status bar I'm referring to:

    Click image for larger version. 

Name:	total.jpg 
Views:	19 
Size:	15.6 KB 
ID:	14415

    Is there a way to create a text box or some type of form control that will display 117? Or, for example, 57 of 117? If it's possible, what do I need to do to create it? Thank you.
    PS: The reason I want to create something like this is so I can have control over the font and size of the number. Warren Page, Access 2013

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Let's say that your Form's control source is a Query named "Query2". Then, on your Form, just add a Text Box, and use the following formula in the Control Source property of that Text Box:
    =Dcount("*","Query2")

    The Dcount function just counts the number of records in some object (Table, Query). You can add criteria (third argument, but it is not required).
    Here is a good write-up on Dcount: http://www.techonthenet.com/access/f...ain/dcount.php

  3. #3
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69
    Thanks for the information. I tried it on one table so far, and it works fine. I'll dabble more with it, but right now, it suits my needs perfectly. Thank you!

    One follow-up question, though: Does the DCount feature work only in forms? Is it possible to put it somewhere in a table? WP

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    One follow-up question, though: Does the DCount feature work only in forms? Is it possible to put it somewhere in a table? WP
    In the older version of Access (prior to 2010), you could not do any calculations in tables. You could only do them in Queries, Forms, Reports, or VBA.
    Even though they now allow you to do them in Tables, many serious programmers still follow the old relational database logic and will not use calculated fields in tables.
    Not a bad practice to follow, especially if you ever need to convert your back-end tables to something like SQL or mySQL someday (they will not support calculations in tables).

  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
    Quote Originally Posted by JoeM View Post

    ...serious programmers still follow the old relational database logic and will not use calculated fields in tables...
    Excellent point! Tables really should be used for one purpose only, to store data, not to manipulate it! Manipulation always carries with it the possibility of corruption rearing its ugly head!

    BTW, if you want to emulate the status bar. i.e. to show 'Record X of Y Number of Records,' you can use something like
    Code:
    Private Sub Form_Load()
      DoCmd.GoToRecord , , acLast
      DoCmd.GoToRecord , , acFirst
    End Sub
    This is needed because the Access Gnomes don't always load the entire RecordSet when a Form first opens. Then to update the count as you move from Record-to-Record:

    For a Label

    Code:
    Private Sub Form_Current()
      Me.LabelName.Caption = "Record  " & CurrentRecord & "  Of  " & RecordsetClone.RecordCount & "  Records"
    End Sub

    For Textbox
    Code:
    Private Sub Form_Current()
      Me.TextboxName = "Record  " & CurrentRecord & "  Of  " & RecordsetClone.RecordCount & "  Records"
    End Sub

    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
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69
    Thanks for the replies. Having this in a table is not necessary for me. I only asked about it purely out of curiosity. The DCount option worked for me quite nicely, right out of the starting gate, first try.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    However, the DCount is counting directly on the table or query and might not agree with the actual count of records on the form if filtering is applied to form.

    Calculated field type (Access 2010 up) in table will not allow use of functions.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  2. limiting amount of records
    By yaro.kobzar in forum Programming
    Replies: 1
    Last Post: 05-17-2011, 07:01 PM
  3. Replies: 5
    Last Post: 05-14-2011, 04:31 AM
  4. Replies: 4
    Last Post: 12-01-2010, 02:42 PM
  5. Report displays no records
    By windwardmi in forum Reports
    Replies: 5
    Last Post: 10-05-2010, 12:10 PM

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