Can I reference a form field to get a variable and use it in a query?

W

wazza_c12

Hi All

This has me stumped, I want to try and do the following, but am unsure
if it is possible.

A query that goes like

SELECT FIELDS
FROM TABLES
WHERE tablename.("[Forms]![formname]![textbox]") = "value"

I am trying to pull a variable fieldname out of an open form and use it
in a query, however I do not know if this is possible or if it is what
the syntax would be.

I have read posts about using eval() or public functions but have got a
little lost with it all.

I suppose I could do the whole thing in VBA, but it's a large query and
I thought there may be a simple way to sort it out in SQL

Any help would be much appreciated.

Cheers

Warwick
 
J

John Vinson

I suppose I could do the whole thing in VBA, but it's a large query and
I thought there may be a simple way to sort it out in SQL

Fraid. not. You can use parameters for calculated fields and
expressions in calculated fields; you can use parameters in criteria;
but you can't use parameters to select the table name.

The need to do so in the first place REALLY makes me worry about your
database design - storing multiple similar tables differing only in
the tablename is a Very Bad Idea!

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top