Results 1 to 7 of 7
  1. #1
    rdougherty is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2016
    Location
    Michigan
    Posts
    107

    Display a count of records on Form or Report

    I have a requirement to set up a form or report to count and sum values from a particular table. I do NOT wish to display any of the records from that table as the Record Source. I simply want this one-page form to show me a few variables or results of functions called.

    I am having some trouble deciding which method to use for counting records meeting criteria.

    Count records in table where field1 = "PAYENM"
    Code:
    DCount("[field1]", "raw_text_file", "[field1]" = "PAYENM")
    this will be our count of payees, which we are QC'ing and documenting on a log sheet before uploading to an eBanking system.

    Once I can get tihs to work, I'll probable be able to figure out more things to count and/or sum.



    Thanks,

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    705
    I do dashboards to display totals and summaries.

    The dashboard form is unbound. I uses unrelated sub form(s) and/or sub report(s) to display totals, summaries, and graphs.

  4. #4
    rdougherty is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2016
    Location
    Michigan
    Posts
    107
    thanks for the info!

    As a follow up question, what is the best way to prevent the controls on the form from calling the variables before another button on the form populates a table that these variables are evaluating themselves based upon?

    For instance, I do not want these controls either showing #error etc. or giving the "Improper use of Null" which a DSUM variable is throwing, because it doesn't have anything to sum.

    Would it be to make them all invisible when the form loads, and then make them visible after the import button populates the table?

    OR

    would it be best to make these form controls not use the variables as control sources, but define them with one of the variables as a source immediately after the import button is finished and table populated?

    Please advise! (thanks in advance)

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    705
    Quote Originally Posted by rdougherty View Post
    thanks for the info!

    As a follow up question, what is the best way to prevent the controls on the form from calling the variables before another button on the form populates a table that these variables are evaluating themselves based upon?

    For instance, I do not want these controls either showing #error etc. or giving the "Improper use of Null" which a DSUM variable is throwing, because it doesn't have anything to sum.

    Would it be to make them all invisible when the form loads, and then make them visible after the import button populates the table?

    OR

    would it be best to make these form controls not use the variables as control sources, but define them with one of the variables as a source immediately after the import button is finished and table populated?

    Please advise! (thanks in advance)

    When importing the data to a temp table(s) for the dashboard I would also make sure that there is always records even if the numbers are all zero (o). Then your DCount() will also work.

    I also do as much of the totaling in the temp tables as possible. This allow for simple bound sub forms and sub reports.


    About screen updating, this is another reason why I use a bound sub report or sub form whenever possible. Before the import, I turn off screen updating. Import the data. Requery the form. turn on screen updating.

    I avoid using Domain Functions like DCount() and DSum(). As you are experiencing, they require extra VBA code to validate that they will return something before using them. I prefer to gather all my statics with a query.

    You might also find this helpful: Using Dashboard Graphics in Access

  6. #6
    rdougherty is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2016
    Location
    Michigan
    Posts
    107
    follow up: the problem ended up being that the values were not technically Null, but zero rows from which to evaluate Null.

    The solution was actually very simple and uses very little additional code:

    (this tests whether a table is populated True/False)

    Code:
    Public Function textfile() As Boolean
        Dim r As DAO.Recordset
        
        Set r = CurrentDb.OpenRecordset("raw_text_file")
        If r.RecordCount > 0 Then
        textfile = True
        Else
        textfile = False
        End If
        
    End Function
    Then use that Y/N to evaluate whether each count, sum, should occur or not.

    Code:
    Public Function PaymentSum() As Double
        If textfile = True Then
        PaymentSum = DSum("[field5]", "raw_text_file", "[field1] = 'PMTHDR'")
        Else
        Exit Function
        End If
    End Function

  7. #7
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    705
    Thanks for the update and sharing your solution so other may benefit.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2016, 01:07 PM
  2. <Solved>Count how many records display 0
    By tareyj8569 in forum Access
    Replies: 9
    Last Post: 08-03-2015, 10:10 PM
  3. Open Form and Display Record Count
    By MatthewR in forum Forms
    Replies: 7
    Last Post: 07-02-2015, 02:34 PM
  4. Replies: 2
    Last Post: 04-30-2013, 07:55 PM
  5. Replies: 6
    Last Post: 07-25-2011, 01:54 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