Results 1 to 11 of 11
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    Criteria issue with DCount

    I have a list box to select a list winners using a combo box. Everything works a it should so far. I want to add a count of the number of winners in the selected list using DCount. I can't get the criteria to work.

    The first expression works and gives me the total count in the table, the second one is the one I want to count only the selected records but I get an #Error, ans I have not been able to resolve the issue.

    Code:
    =DCount("[Winner]","F1PoleT")
    Code:
    =DCount("[Winner]","F1PoleT","Winner=" & [WinnerCmb])
    Thanks
    Jim O

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The criteria will be the same as the criteria used in the row source for the list box.

    Is this in the Control Source of a textbox? If so, it need to reference the form:
    Forms!Formname!cmbWinner

  3. #3
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    There is no specific criteria for the list box.

    Code:
    SELECT [PoleTImeID], [RaceDate], [Winner], [Const], [Race] FROM F1PoleT ORDER BY RaceDate;
    Jim O

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I have a list box to select a list winners using a combo box
    How does the list box tie in to the combobox?

  5. #5
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    My mistake the criteria was in the como box event.

    I am no sure how to use it in the expression.

    Code:
    WHERE [Winner] LIKE '" & Me.WinnerCmb & "'
    Jim O

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Where is the expression being used?

  7. #7
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    It is in a combo box [WinnerCmb] as an after update event to select the list.

    Code:
        WinnerList.RowSource = "SELECT [PoleTImeID], [RaceDate], [Winner], [Const], [Race] FROM F1PoleT WHERE [Winner] LIKE '" & Me.WinnerCmb & "' ORDER BY RaceDate;"

    Jim O

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I meant, for the DCount, the one mentioned in post # 1.
    (Did you see post #2 edited?)

  9. #9
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    This is what I have for the expression and I get a #Error.

    Code:
    =DCount("[Winner]","F1PoleT","Winner=" & [Forms]![F1WinnersListF]![WinnerCmb])
    Jim O

  10. #10
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In other posts you have showed that your combobox is a text field, so you need quotes:
    Code:
    =DCount("[Winner]","F1PoleT","Winner='" & [Forms]![F1WinnersListF]![WinnerCmb] & "'")

  11. #11
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    That is what I need. Thank you so much for the help (all who responded). As a relative beginner with Access I appreciate the time an knowledge on this page.

    Thanks again.

    Jim O

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

Similar Threads

  1. Need a fresh set of eyes please (Dcount issue)
    By Gina Maylone in forum Access
    Replies: 3
    Last Post: 02-23-2017, 03:12 PM
  2. Using DCount, how to use a variable as the criteria
    By crowegreg in forum Programming
    Replies: 2
    Last Post: 02-17-2015, 05:18 PM
  3. Replies: 2
    Last Post: 02-26-2014, 05:06 PM
  4. DCount issue
    By RobWulf in forum Queries
    Replies: 4
    Last Post: 05-21-2013, 04:07 PM
  5. Replies: 1
    Last Post: 05-18-2012, 11: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