Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48

    run a sum query on an id in a combobox

    Hi
    i have an athlete db


    i have a form with a combo box
    i want a cell to tell me how many races an athlete has had once i pick the athlete in the combo box
    there is also a cell with the date in it
    i want the "how many races cell" to only show the number of races the athlete competed in before the date in the "date cell"
    thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Could use DCount in textbox ControlSource.

    =DCount("RaceID", "Races", "AthleteID=" & Me.comboboxname & " AND " & "RaceDate<#" & Me.datetextbox & "#")
    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.

  3. #3
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    cant get it to work june. comes up with 'name?, the combobox is unbound and its a subform im working with is this the issue

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Show the exact expression you used. I assume you use your fields and control names. Are the combobox, ID, and RaceDate all on the subform?
    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
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    =dcount("*", "Race Results", "Athlete Id" = & [Me].[Combo35]) and a million other variations the only thing on the subform is the athlete id combo box. the main use of the subform is to put in all the athletes on the form with there results for the day etc. then i'll macro each one into the race results form. but i want to show how many races they have run in up to that date
    eg
    ath 1(combobox) 5 races so far today came 1st time
    ath 2 2 races so far today came 4th time
    ath 3 12 races so far today came 6th time

    where races so far is the text box i want to populate when the athletes name is selected from the combo box

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Race date is on main form? You actually have space in the Athlete ID field and Race Results table names? Advise to avoid using spaces and special characters in any names. If you do, must remember to enclose in []. Athlete ID is a number datatype field?

    =DCount("[Athlete ID]", "[Race Results]", "[Athlete Id]=" & Me.Combo35 & " AND RaceDate<#" & Forms!mainformname.datetextboxname & "#")

    or if textbox with this expression is on main form:

    =DCount("[Athlete ID]", "[Race Results]", "[Athlete Id]=" & Me.subformcontainername.Form.Combo35 & " AND RaceDate<#" & Me.datetextboxname & "#")

    I always give subform containers a name different from the object they hold, like: ctrResults.
    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
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    =DCount("[Athlete ID]", "[Race Results]", "[Athlete Id]=" & Me.Combo35) Didnt work June even tried to shorten it as shown to take out the date aspect and no luck with it working. Changed the expression to "*", didnt work,, took out criteria and finally got a value but its just counting the number of all records....hmmmmm. seems like the criteria might b it. any other ideas.. the textbox is in the sub form also..

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Textbox and combobox are on subform? Is Athlete ID a text or number data type? If it is text need apostrophe delimiters.

    =DCount("[Athlete ID]", "[Race Results]", "[Athlete Id]='" & Me.Combo35 & "'")

    You want to provide project for analysis?
    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.

  9. #9
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    athlete id is text june sorry what are the apostrophe delimiters

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    They define the value as a text string. I show the syntax in previous post. Dates require # and numbers nothing.
    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.

  11. #11
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    Still no luck June still comes up with NAME? in text box..i tried just as you typed out..hhmmmm

  12. #12
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    its something to do with the criteria, when i remove it it gives me the value of entries in the domain but as soon as i try to add criteria no luck

  13. #13
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    ok June got it..... this is it...=DCount("[Athlete Id]","[Race Results]","[Athlete Id]='" & [Combo35] & "'").. now if i could get your advice on how to add on the part about only count the records that are before a certain date in a text box on the main form..
    thanks

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I showed example of that in post 6.
    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.

  15. #15
    gbmarlysis is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    48
    the date isnt its own field. it is used as the race primary id eg lathl15/06/11r1 can i use wildcards in dcount? how would this look.
    (the reason i did this is when i want to see a race result i know the date and race no and who hosted the meet so i can put that in a combo box to recieve the results)

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  2. Replies: 29
    Last Post: 08-16-2011, 05:52 PM
  3. Replies: 6
    Last Post: 07-28-2011, 04:07 AM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 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