Populating a Combo Box with a list of fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mattandlisa3
    New Member
    • Nov 2008
    • 3

    Populating a Combo Box with a list of fields

    Is there a way to populate a combo box with a list of fields from a table or query? My purpose in doing this is to allow a user to select a field to search.

    Also, does anyone have any advice as to the best way to make it so a user can select multiple search criteria? My plan was to just make 5 combo boxes as mentioned above, so people can run searches based on up to 5 criteria. However, I would like to make it so they can use any of the boolean operators in their search. I'm not sure on the best way to go about doing this. Any ideas?

    Thanks!
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello.

    Table and query properties (including fields collection) are accessible via correspondent TableDef and QueryDef objects respectively.
    Collections containing TableDef and QueryDef objects are accessible via Database.TableD efs and Database.QueryD efs properties respectively.

    As for your 2nd question, you may look at a similar thread.

    Regards,
    Fish

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by mattandlisa3
      Is there a way to populate a combo box with a list of fields from a table or query? My purpose in doing this is to allow a user to select a field to search.

      Also, does anyone have any advice as to the best way to make it so a user can select multiple search criteria? My plan was to just make 5 combo boxes as mentioned above, so people can run searches based on up to 5 criteria. However, I would like to make it so they can use any of the boolean operators in their search. I'm not sure on the best way to go about doing this. Any ideas?

      Thanks!
      The answer to Part #1 is a simple 3 step process:
      1. Create an Unbound Combo Box
      2. Set its Row Source Type to Field List
      3. Set its Row Source to your Table or Query whose Fields you wish to search

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        If you want your user to be able to pick a number of criteria and then choose AND or OR of all of them, it might not be too difficult to build a criteria string.

        strOperator = " AND " or " OR " based on a user choice
        then
        strSQL = "SELECT * FROM MyTable WHERE " & Criteria1 & strOperator & Criteria2 & strOperator & ect...

        But I have a feeling you want to do something more complicated.

        Comment

        Working...