Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013

    Question Unanswered: query criteria from combo box in table

    I am a noob when it comes to this. I am trying to get a query to select only a typed in location from a table. the locations are in a drop down box. any help on this would be much appreciated.

  2. #2
    Join Date
    Jul 2009
    I'm not sure exactly what you mean, but I'm guessing either one of these 2 scenarios:

    1) After selecting a value in dropdown box #1 (location), you click a button and a query is generated with filter based on that value.

    2) You want a second dropdown box to show a list based on the value of the first dropdown box.

    For the first case, let's say you have a Form called form_name and the dropdown box is called location. (Yeah, I'm out of creative juice atm. )
    Put the following code for the OnClick property of the button (or AfterUpdate of the dropdown, whichever floats your boat):

    Dim strsql As String
    Dim tempQuery As QueryDef
    strsql = "SELECT * FROM table_name WHERE location = '" & Forms!form_name!location & "'"
    Set tempQuery = CurrentDb.CreateQueryDef("tempQuery", strsql)
    DoCmd.OpenQuery "tempQuery"
    For the second case, you would use the AfterUpdate property of the first dropdown box, with a code something like:

    Me.dropdown_box2.RowSource = "SELECT city_name FROM cities_table WHERE location = '" & Me.location & "'"
    where "city_name" is the column from table "cities_table" you want to show based on what is type in the first dropdown box.

    HTH. If my example is unclear, please reply with a clearer structure of how your table/form looks and I can be more specific with field names.
    Financial guy by trade, software tinkering by hobby

    PC : Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz, 4GB RAM
    Windows 7 Professional 32-bit SP1
    MS Office 2010

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