Results 1 to 5 of 5
  1. #1
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169

    Query to count records

    I am trying to run an update query to count the number of records in a related table and store the count in the main table. For example: I have a table with inquiries (tblInquiry) with a field ResponseCount. I have another table (tblInquiryReply). I am trying to run the attached code but apparently I am doing something wrong once again.


    Code:
    DoCmd.RunSQL "Update tblInquiry set tblInquiry.ResponseCount = Count(InquiryRespID) from tblInquiryReply where tblInquiry.InquiryID = " & Me.InquiryID
    I am getting an error that states: The expresion you entered refers to an object that is closed or dosen't exist. (Run-time error 2467). Is my code way off or am I close?

    Thanks.

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Try something like this:

    Code:
    DoCmd.RunSQL "Update tblInquiry set tblInquiry.ResponseCount = Count(InquiryRespID) from tblInquiryReply where tblInquiry.InquiryID = " & Chr(34) &  Me.InquiryID & Chr(34)

  3. #3
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Thanks Slave for taking a look. I tried the code as you suggested. I am now getting the following error message:

    Run-time error '3075':
    Syntax error (missing operator) in query expression 'Count(InquiryRespID) from tblInquiryReply

    Any thoughts anybody?

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I may be missing something but I don't think you can use an aggregate function (Count) as part of an Update query.

  5. #5
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    OK, I will try some other way to accomplish what I need. Thanks for your input.

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

Similar Threads

  1. Count distinct records in parameterized query
    By SilverSN95 in forum Access
    Replies: 5
    Last Post: 07-27-2010, 09:31 AM
  2. Replies: 7
    Last Post: 07-22-2010, 01:14 PM
  3. Count of records
    By Aston in forum Access
    Replies: 2
    Last Post: 03-30-2010, 05:20 AM
  4. Count of records
    By Bruce in forum Forms
    Replies: 3
    Last Post: 03-22-2010, 01:30 PM
  5. Count records issue
    By EstesExpress in forum Forms
    Replies: 1
    Last Post: 09-29-2009, 12:24 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