Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

controlling what column to SELECT from Combo Box

Status
Not open for further replies.

finafisken

Programmer
Jul 10, 2001
5
SE
Hi everybody!

My problem is that I need to give the user control over which column that will be displayed in an Access 97 query. I thought that a Combo Box would be perfect for this as it works perfectly when sorting out different posts using WHERE. However, this seemed not to be the case at all...

This is how I hade HOPED for it to work:

SELECT TAvkastning.foretag, TAvkastning.[Forms]![SharperatioForm]![Foretag]]
FROM TAvkastning
WHERE TAvkastning.Foretag LIKE ([Forms]![SharperatioForm]![Foretag])

Is there any way to do this in SQL code at all?








 
1. Create a combo box with the column names.
2. Create a list box to display the column.
3. In the combo box's click event add SQL for the rowsource of the list box as such...

ListBox.RowSource = "SELECT " & ComboBox & " FROM MYTABLE"

Now whatever is in the combo box will be the column that your list box will display.

Hope this is what you were wanting.

B-) ljprodev@yahoo.com
ProDev
MS Access Applications
 
this was ALMOST what I wanted...

The root of my problem is that SQL won't accept that SELECT tries to retrieve a variable.

 
Are you using Access97. I can email you a sample. Again let me make sure I understand. You want to be able to select a coulumn name or field that exist in a table from a combo box. Once the item is selected you want the data that is in that column to show in a list box.

If so, email me at the address below and I'll send it to you.

B-) ljprodev@yahoo.com
ProDev, MS Access Applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top