Computing.Net > Forums > Office Software > Value of combo box as field in SQL

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Value of combo box as field in SQL

Reply to Message Icon

Name: Martyn999
Date: June 29, 2005 at 12:24:39 Pacific
OS: Windows XP Pro
CPU/Ram: Athlon64 3500+ / 1GB
Comment:

I have a database table which contains client information. I have created a form where you use a dropdown box to choose a field to search by, then type the criteria in a box. There is only one box for the criteria.

I am trying to create a query in Access which will perform the search and return the results. I can easily make one which will return accurate results if I hard code the field name 'Address' in for instance, ie using '... where Address = txtcriteria'. The difficult part is though, I don't want to hard code the field name in. I want it to be read from the forms drop down box. I have tried SQL such as '...where cbofield = txtcriteria'. This doesn't work though, and I get no results returned.

I know I could do it in VBA by reading the value of the dropdown box and running a different SQL statment for each possible option, but surely it can be done in 1 SQL statment where this reads the value? All I need to do is use the value of a combo box instead of hard coding a field name...

Any ideas?



Sponsored Link
Ads by Google

Response Number 1
Name: smithdk
Date: June 29, 2005 at 15:42:51 Pacific
Reply:

If I understand you correctly, you want the query to get the value from the combo box in the form. In the query, use [forms]![formname]![comboname] in the criteria portion for the field. Is this what you are looking for?


0

Response Number 2
Name: Martyn999
Date: June 30, 2005 at 00:22:09 Pacific
Reply:

Thats what I tried, although it does not work :(

I resorted to using VBA in the end though as that allows variable names and I can do it that way. :P


0

Response Number 3
Name: StuartS
Date: June 30, 2005 at 16:50:08 Pacific
Reply:

Use this:

" ... WHERE cbofield = " & Combo1.List(Combo1.ListIndex)

Combo1.listindex returns a number that indicates the item on the list that is selected.

Stuart


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Value of combo box as field in SQL

Combo Box in Access www.computing.net/answers/office/combo-box-in-access/3477.html

Clearing combo boxes in access www.computing.net/answers/office/clearing-combo-boxes-in-access/5413.html

Access 2002 combo boxes www.computing.net/answers/office/access-2002-combo-boxes/258.html