Results 1 to 3 of 3
  1. #1
    vclink is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Location
    Des Moines, Iowa
    Posts
    5

    Using IN with a parameter and field

    I am trying (unsuccessfully so far) to an IN with a field and parameter in my WHERE of my query. Here's the story. My database is information about international business trips. It keeps track of who is travelling, what flights, hotels, etc. I have a tables for the individuals' "profile" info, trips, flights, hotels, and then trip info specific to a trip tied to an individual and their various flights/hotels/etc for that trip. The trips are often to multiple countries but sometimes travelers only participate in one portion of the trip (to one country). We currently have a field called Participation in which we enter the initial of the country(s) in which the traveler will participate. When we produce listings of trip participants I'd like the option of using that field to create a list of those who will visit that country. Adding to the detail, I also want to be able to leave that parameter empty and get all travelers for the trip regardless of the countries in which they are participating. Example:

    Trip to Korea and China. In the participation field (a short text field) traveler A has K (indicating they are travelling to Korea only on this trip); traveler B has K, C; traveler C has K; traveler D has C. I want to be able to run the query (which asks for the trip name already) and have a parameter for country initial. If I enter nothing, I get travelers A, B, C and D. If I enter C, I get only travelers B and D. If I enter K, I get only travelers A, B and C.

    I have tried the following in my query, and while it runs and seems to correctly ask me for input, I get no results unless I don't enter anything in the parameter, then I get all for that trip.

    WHERE ([TripInfo.Participation])=Nz((('*' + [Enter Country Initial:]+'*') IN ([TripInfo.Participation])), [TripInfo.Participation]))

    I think I'm saying give me all the travelers where the initial I enter when prompted is in the field Participation or, if I don't enter anything, give me all travelers.



    Any helpful hints? Is there a different way I should/could be querying to get the results I want?

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Look like you got you syntax mixed up.

    When using "*" (wildcard), you need to use key word "LIKE".
    When using "IN", you need to supply with a list.
    '+' is adding, '&' is concatenate.

    It would be something like this.

    WHERE ([TripInfo.Participation]) LIKE '*' & TRIM([Enter Country Initial:]) & '*'
    AND [TripInfo.Participation] IN ([Participation1], [Participation2], ... etc )

  3. #3
    vclink is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Location
    Des Moines, Iowa
    Posts
    5
    THANK YOU! That works perfectly!

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

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2012, 03:52 PM
  2. Can I use a Parameter on a Date/Time Field?
    By Paul H in forum Queries
    Replies: 5
    Last Post: 04-24-2012, 03:12 PM
  3. use parameter in field name of select query
    By focosi in forum Queries
    Replies: 2
    Last Post: 02-11-2012, 10:34 AM
  4. Parameter field in Form
    By darryaz in forum Forms
    Replies: 2
    Last Post: 11-20-2011, 12:38 PM
  5. Parameter Query on a calculated field
    By l3111 in forum Queries
    Replies: 5
    Last Post: 10-12-2011, 02:18 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