Results 1 to 8 of 8
  1. #1
    TUPJK is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    17

    If __ Then __ type commands in queries?

    I have 2 forms, one nested within another

    One is an ID form, the other is drug injection order for that ID model

    So say model #1, #2, #3, #4, #5, #6 all receive 20 various drugs

    But only #2-6 receive a drug "GTN"



    I want to run a query that will search for all models that received a 3mg dose of GTN, but also return EVERY other drug injection order that model received

    So sort of something like [If (model #) receives 3mg of GTN THEN return all records for (model #)]

    type command

    anybody able to help?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Construct a field in query with DLookup then filter on that field.
    DLookup("fieldname","tablename", "Dose='3mg' And ModelNo='" & [ModelNo] & "'")

    Filter would be: Not Is Null

    In this example, 3mg is a literal string and static. Make this dynamic by referring to a control (combobox with LimitToList) on form where user enters dose value to search on.
    DLookup("fieldname","tablename", "Dose='" & Forms!formname.controlname & "' And ModelNo='" & [ModelNo] & "'")
    Last edited by June7; 06-17-2011 at 06:30 PM.
    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
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi TUPKJ,

    I want to run a query that will search for all models that received a 3mg dose of GTN, but also return EVERY other drug injection order that model received

    So sort of something like [If (model #) receives 3mg of GTN THEN return all records for (model #)]
    I think that what you need is a query that queries a query, if that makes any sense to you.
    Create a query that returns all models that received a 3mg dose of GTN. Save this query. Create another query based on the first query joined to the table used in the first query.
    If this gives the result you require then this could be done using a single query and a subquery written in its' SQL.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    TUPJK is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    17
    Quote Originally Posted by June7 View Post
    Construct a field in query with DLookup then filter on that field.
    DLookup("fieldname","tablename", "Dose='3mg' And ModelNo='" & [ModelNo] & "'")

    Filter would be: Not Is Null

    In this example, 3mg is a literal string and static. Make this dynamic by referring to a control (combobox with LimitToList) on form where user enters dose value to search on.
    DLookup("fieldname","tablename", "Dose='" & Forms!formname.controlname & "' And ModelNo='" & [ModelNo] & "'")
    I am a complete novice... what does Dlookup mean?

    is this in SQL view?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    DLookup is a data aggregate function. There is a whole family of these - DSum, DMin, DMax, DAvg, DFirst, DLast.

    Google it or try the Access Help for info.
    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
    TUPJK is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    17
    OK I'm just going to use Bob Fitz's solution and just use a "make table" query, then run a query on that... seems easier

    Writing code is way over my head, I don't even know how to get to the window to start writing it

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I wasn't suggesting code. The DLookup would be an expression in the query. Enter it in the Field row of the designer grid. This will result in a constructed field. This field can be treated like any of the other fields that come from the table.
    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.

  8. #8
    TUPJK is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    17
    I need to watch some youtube videos on how to do this

    in the mean time, I will just be doing queries of queries

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

Similar Threads

  1. missing commands and options dialog box
    By marlowj30 in forum Access
    Replies: 1
    Last Post: 06-15-2011, 01:38 PM
  2. Data type mismatch error on all of my queries!
    By MarkGLyons in forum Queries
    Replies: 3
    Last Post: 12-27-2010, 01:27 PM
  3. Basic commands in Access 2007
    By johnkl49 in forum Access
    Replies: 2
    Last Post: 09-23-2010, 04:07 PM
  4. Replies: 0
    Last Post: 05-14-2010, 07:28 AM
  5. Replies: 0
    Last Post: 09-08-2009, 11:01 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