Results 1 to 2 of 2
  1. #1
    Ekhart is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2016
    Posts
    80

    Counting Records to display on Form

    I have a form that contains buttons to various reports that a user can access. Is there a way to display the count of records on the main form? I currently have them display inside each report but would like people to know if they actually need to look at a report or not.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try this: It won't clutter your form with textboxes.
    This function will show a message box indicating the number of records returned by the report query. It will return true if the recordcount of the report query is greater than zero.
    It will return false if the user clicks Cancel or the recordcount of the report query is zero.
    Call the function before opening the report, supplying the query name as the parameter.
    If the function returns TRUE, open the report.
    You can put this query in the form's code or in a module if it will be needed by more than one form.


    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : fcnCountOK
    ' DateTime  : 7/9/2014 16:41
    ' Author    : davegri
    ' Purpose   : Count number of records returned by a SELECT QUERY
    '   and display the result in a message box
    '---------------------------------------------------------------------------------------
    '
    Function fcnCountOK(qQuery As String) As Boolean
        Dim reccnt As Long, intMsgBox As Long
        On Error GoTo fcnCountOK_Error
        fcnCountOK = True
        reccnt = DCount("*", qQuery)
        intMsgBox = MsgBox("This selection will process " + Str(reccnt) + " records", _
        vbOKCancel, "     R E C O R D S   T O   P R O C E S S     ")
        If reccnt = 0 Or intMsgBox = vbCancel Then
            fcnCountOK = False
        End If
    fcnCountOK_Exit:
        Exit Function
    fcnCountOK_Error:
         Msgbox Err.Number & ", " & Err.Description & ", in fcnCountOK"
        Resume fcnCountOK_Exit
    End Function
    Last edited by davegri; 08-01-2016 at 10:18 PM. Reason: fix error handler

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

Similar Threads

  1. Counting values then display the sum
    By shod90 in forum Forms
    Replies: 1
    Last Post: 03-04-2016, 05:23 PM
  2. Replies: 1
    Last Post: 09-02-2015, 01:16 AM
  3. Replies: 8
    Last Post: 05-10-2015, 06:24 PM
  4. Replies: 10
    Last Post: 02-09-2012, 04:42 PM
  5. Display ALL records in a form?
    By evander in forum Forms
    Replies: 3
    Last Post: 07-15-2010, 07:59 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