Results 1 to 7 of 7
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Dcount records from a filtered form

    Hello everyone

    I have the next question

    How can I count the records I have into the field from a filtered form



    The way I tried to do was with the function Dcount

    My code is:
    Me.Passtxt = DCount("[TotalResult]", "[qryResults]", "[TotalResult]= 'Pass'")
    Me.Failtxt = DCount("[TotalResult]", "[qryResults]", "[TotalResult]= 'Fail'")

    It works pretty good for the data of the query... qryResults...

    But I would like that will be calculated by the currentform named "qryResultsForm"

    Thanks in advance for the support!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    fields have brackets, not queries,
    try

    Me.Passtxt = DCount("*", "qryResults", "[TotalResult]= 'Pass'")
    Me.Failtxt = DCount("*", "qryResults", "[TotalResult]= 'Fail'")

  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Thank you ranman

    But it is still taking the info from the query "qryResults" and it's not taking the info from the "qryResultsForm" which is being filtered by a textbox in the form

    How can I solve it?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Textbox in form header or footer with expression in ControlSource: =Count(*)

    Brackets must be used to enclose any (field, table, query, form, report) names when spaces or special characters/punctuation (underscore is exception) are used in the names.
    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.

  5. #5
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    You were right about add this on controlsource = Count(*)

    I've added that to each field controlsource: Passtxt and Failtxt (Unbound) text boxes

    and when I'm filtering the info it shows the quantity of records filtered in the form, but not with the criteria about the quantities of Pass' and the quantities of Fail'

    Why? and how could be it fixed?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Need IIf() expression:

    =Count(IIf([fieldname]="Pass",1))

    =Count(IIf([fieldname]="Fail",1))

    or

    =Sum(IIf([fieldname]="Pass",1))

    =Sum(IIf([fieldname]="Fail",1))
    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.

  7. #7
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Totally right!!

    Thank you!

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

Similar Threads

  1. How to get count of filtered records
    By DBDave in forum Queries
    Replies: 2
    Last Post: 11-03-2014, 02:07 PM
  2. Filtered Report from filtered datasheet form
    By gemadan96 in forum Reports
    Replies: 7
    Last Post: 01-03-2014, 05:12 PM
  3. DCount on filtered subform
    By TheShabz in forum Forms
    Replies: 2
    Last Post: 07-13-2011, 02:22 PM
  4. Open form to filtered records
    By ducecoop in forum Access
    Replies: 3
    Last Post: 10-22-2010, 10:53 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