Results 1 to 7 of 7
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Any way to get a count of matching records from another table while in a continuous form

    I have a continuous form that has a car id in the form. I would like to get a count of the matching car id's in another table based on the active records car id.



    For example:
    Each line item in the continuous form has an car id. I would like to count the number of active records in another table based on the active car id.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Sounds like need a domain aggregate function like DCount(). Search Access Help or Google for specifics on domain aggregate functions.
    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
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If you are not going to be updating the data in that form, the other way you could do this is base the form on a Totals query linking the two tables, and which has a Count on the CarID from the second table, and Group By on all the fields from the first table.

  4. #4
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    I cant use dcount because it is on a continuous form and the value I want to use as a filter is the field value on the current line in the continuous form.

    So in my continuous form each line is for a car. I want to use that car id as a filter to get a count of the records in an alerts table. So in laymens terms: if current line is for car 12 then look at the alerts table and show me how many total alerts there are for car 12 and display it.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Yes, so in a textbox next to that carID textbox: =DCount("*", "tablename", "carID=" & [carID])

    Is carID a number type field?
    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.

  6. #6
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Ok, thanks, well that works. I was told previously that a dsum or count wont work on a continuous form. I guess that is wrong or only in certain cases.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    It would not work if you used VBA code to calculate with the DSum and set textbox Value property. Every record would show the same value because there is only the one control. Property settings are reflected in every instance of a control. Expression in ControlSource property allows dynamic reference to the carID by concatenating. The carID is treated as a variable.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-09-2017, 04:50 PM
  2. Replies: 23
    Last Post: 01-27-2016, 01:42 PM
  3. Replies: 2
    Last Post: 12-22-2015, 09:09 PM
  4. Replies: 1
    Last Post: 10-24-2011, 08:01 AM
  5. Replies: 1
    Last Post: 04-02-2011, 11:55 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