Results 1 to 3 of 3
  1. #1
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    50

    Assigning a value to a variable based on the Count of another variable

    Hello all,



    It seems like this should be easy enough to do, but of course it's not.

    I'm essentially trying to assign my cohort of patients into two groups based on how many medications they were discharged on. I've created a query called "qryGroups" in order to do this. I am pulling the values "PatientID", "Drug" and "AsNeeded" from a table called "tblDCDrugs".

    My query looks as follows:

    Field: PatientID Drug AsNeeded
    Table: tblDCDrugs tblDCDrugs tblDCDrugs
    Total: Group By Count Group By
    Criteria: False


    I tried to create a variable called "Group", with the syntax "Group: IIf("CountOfDrug">1,1,2)" but I got the error message "Data type mismatch in criteria expression". I would like to assign patients with >1 Drug to Group 1, and all other patients to Group 2. Any thoughts on how I might go about doing this?

    Any help is appreciated!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    First, don't put field name within quotes, use [].

    Second, AFAIK, can't use a field created by aggregate calculation in another expression in same aggregate query.

    Use the grouping query as source for another query.
    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
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    50
    /facepalm

    Don't know why I didn't think of that...thanks June7! Worked like a charm.

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

Similar Threads

  1. using ADO, assigning a date variable
    By crowegreg in forum Programming
    Replies: 3
    Last Post: 08-23-2011, 12:00 AM
  2. assigning a variable
    By crowegreg in forum Programming
    Replies: 1
    Last Post: 08-22-2011, 05:55 PM
  3. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  4. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 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