Results 1 to 10 of 10
  1. #1
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93

    Use a form to tailor query results


    I would like to use a form to tailor query results. I can do this by entering [Enter some criteria] in the conditions box of the query, but I would like the resulting message box to be a combo box. Can you help me with this?

    Thank you in advance for your time and help. Have a great day!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sounds like you already know the answer. You have to use a form if you want a combo box. There's no way with the [Enter...] method. Use a form and your criteria becomes:

    Forms!FormName.ComboName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    @pbaldy

    Thank you for your reply. I don't know where I would be without your help. however, I am not sure what you mean. Where would I put that code?

    What I have:
    qryDateMax
    -EmployeeName
    -Date
    -CourseName
    -CourseStatus
    -FinalScore

    This pulls the max date for all records in tblTraining. I would like to have a form that will filter based on one or any combination of the above criteria. The end result will be a "Print Report" command button that will do just that, but one step at a time. First I need to get the right data, then I will worry about the report.

    Thanks again for your help!!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You replace

    [Enter some criteria]

    with

    Forms!FormName.ComboName

    adjusting for the actual names of course. The form must already be open when the query runs. Typically you'd have a form where the user enters the criteria, with a button to open the report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    So the combo boxes would be bound to tblTraining, I assume? Or would it be to qryDateMax?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It would probably not be bound to anything (no control source). It would have a row source that got the selections you wanted it to present to the user.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Ok...I feel like an idiot. Long day, sorry. In this scenario, if a user left a cbo blank, will that return all records for that criteria, or exclude them all? Just wondering how much control I can give to the user without causing myself headache with a million "It is not showing any results" emails.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use this technique:

    http://www.mvps.org/access/queries/qry0001.htm

    Personally I tend to use that when there are only a couple of options. I typically create dynamic SQL or a wherecondition when there are numerous optional criteria. Can't say why, that's just my preference.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Ok...I tried. Didn't work. Copied the code exactly (replacing the form/cbo names of course) and still only works if all cbos are filled. Where can I go to learn how to create a dynamic SQL?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The sample db here demonstrates modifying the SQL of a subform, and the tutorial isn't bad (I didn't write it):

    http://www.baldyweb.com/BuildSQL.htm

    To open a report, I'd do something similar but only build a string to use in the wherecondition argument of OpenReport (just the WHERE clause portion of the string, without the word "WHERE").
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  2. Display Query Results on a Form
    By P5C768 in forum Queries
    Replies: 5
    Last Post: 05-04-2010, 11:04 AM
  3. Open form based on query results
    By RobbertH in forum Queries
    Replies: 1
    Last Post: 02-10-2010, 08:13 AM
  4. display query results in a form
    By P5C768 in forum Queries
    Replies: 3
    Last Post: 08-14-2009, 03:02 PM
  5. Entering query results in a form
    By marcello.dolcini in forum Forms
    Replies: 0
    Last Post: 04-15-2007, 06:01 PM

Tags for this Thread

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