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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use combobox as fieldname in query (without using VBA)

Status
Not open for further replies.

easyit

Programmer
Aug 22, 2003
443
NL
Hi,

I have a form with a combobox. The combobox third column contains a textvalue that I would like to use as a fieldname in a query. Is this possible?

I use this for returning the combovalue
Code:
(Eval('[Forms]![frm_Main]![cmbCustomer].column(2)'))

The table name is P.

I tried
Code:
Expr1: [P].[(Eval('[Forms]![frm_Main]![cmbCustomer].column(2)'))]
and:
Code:
Expr1: [P].[" & (Eval('[Forms]![frm_Main]![cmbCustomer].column(2)')) & "]

Is my syntax wrong or is it not possible like this? I do not want to use VBA due to maintenance of the queries.


EasyIT

"Do you think that’s air you're breathing?
 
forum702?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
hmmm, not sure about that...

EasyIT

"Do you think that’s air you're breathing?
 
It is a query, isn't it?


EasyIT

"Do you think that’s air you're breathing?
 
For me, Eval is an Access.Application method, not an JetSQL function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Even so, when used as a criteria it works. Or even if used as field it will return the string that is selected in the combobox. So it seems (almost) possible to use the string as a field in a select query as well.





EasyIT

"Do you think that’s air you're breathing?
 
Maybe my question isn't clear enough; the values in the combobox are the field names of a table. Instead of writing the SQL in VBA I would like to get make the field name in the select query variable.

Is it possible at all?

EasyIT

"Do you think that’s air you're breathing?
 
EasyIT said:
... I would like to get make the field name in the select query variable

'Fraid not. The only things that you can supply to a query are data values. You cannot supply SQL predicates, operators, table names, field names or any other thing that is part of the SQL syntax. The reason is that a stored query is pre-compiled, lacking only the data values that are determined when you run it.

If you need to do this then you will have to resort to building the SQL that you want using VBA and then set that as the SQL for the query using a QueryDef object.
 
OK, if thats the case I'll switch to VBA.

Thank you all for the responses!



EasyIT

"Do you think that’s air you're breathing?
 
If you have a limited number of columns, you can create a Row Source like:
[tt]
1 City
2 State
3 Address
4 First Name
5 Last Name
[/tt]
You can then use an expression in the query like:
Code:
Choose([Forms]![frm_Main]![cmbCustomer], [City], [State], [Street], [FName], [LName]) As SelectedField

Duane
Hook'D on Access
MS Access MVP
 
Hi Duane,

Thank you for mentioning this possibility. I have already implemented the VBA option, but will experiment with thsi as well.

regards,

Maarten


EasyIT

"Do you think that’s air you're breathing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top