Consulting

Results 1 to 5 of 5

Thread: Solved: Using SQL to build a drop-down list

  1. #1
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location

    Solved: Using SQL to build a drop-down list

    OK..I am really out of my element here...but..

    it is possible to build a dropdown list in which the choices are called out in the SQL statement? and what would that statement look like?

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Sure is. It's any valid Select Query. If the select query contains more than one column it uses the columns left to right depending on how many columns you set up your ComboBox/ListBox/ListView control to use. Columns exceeding the ComboBox.ColumnCount Property are just ignored. It's generally best to pull in only the column(s) you need though.
    SELECT [MyTable].[MyField]
    FROM [MyTable]
    ORDER BY [MyField];
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location
    Oorang..you missed, probably due to me not be clear, the real thrust of my question. I know it can be done that way...my question is with without having the choices in a table...but having them listed out in the actual SQL statement.

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    OIC AFAIK you can only "hard code" columns. You could try to pull something off with a crosstab, but remember aggregate only return numbers, so if your combobox is not numeric you're out of luck. Beside, that's asking to get shot by however has to maintain your code

    There might be an alternative, what problem are you trying to solve?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by GoKats78
    my question is with without having the choices in a table...but having them listed out in the actual SQL statement.
    Do you mean the list exists as either a multi-select combo or listbox, then the choices are concatenated into an In("choice1",..."choice_n") or just a multiple WHERE...AND statement???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •