Using a field name as variable in a query

  • Follow


I need to use a field name as a variable in a query.     

I have a table "Contractor List table" with forty-some Yes/No fields titled 
by County names.   (field 6 name = Hamilton, field 7 name = Johnson, etc...)  
 (the first 5 fields are the contractor name, phone, address, etc)  

A form contains a drop down with the field names of the table.   I want to 
design a query to show records where [form..drop down] = -1 (yes).  The 
purpose is to find contractors who will work in a specific county.

So, to restate I want to query like .. if "field name" = -1 then show all 
records.

I thought I could do this, but cannot make the query work.  Any help is 
appreciated.

Thank you,
tp
0
Reply Utf 11/28/2009 1:51:01 PM

You are committing spreadsheet with a relational database. Rethink your 
structure. You need three tables:
Contractor:
    Contractor ID (autonumber PK)
    your 5 fields of contractor attributes
County
    CountyID (Autonumber PK)
    CountyName
ContractorCounty
    ContractorID
    CountyID

    The last table needs a compound PK on ContractorID and CountyID

Your drop-down can thn show the County Names from the County table, without 
the need to reference field names in a query.

-TedMi

"Titlepusher" <Titlepusher@discussions.microsoft.com> wrote in message 
news:8D427793-3B80-41D3-A689-42FA723D3A3C@microsoft.com...
>I need to use a field name as a variable in a query.
>
> I have a table "Contractor List table" with forty-some Yes/No fields 
> titled
> by County names.   (field 6 name = Hamilton, field 7 name = Johnson, 
> etc...)
> (the first 5 fields are the contractor name, phone, address, etc)
>
> A form contains a drop down with the field names of the table.   I want to
> design a query to show records where [form..drop down] = -1 (yes).  The
> purpose is to find contractors who will work in a specific county.
>
> So, to restate I want to query like .. if "field name" = -1 then show all
> records.
>
> I thought I could do this, but cannot make the query work.  Any help is
> appreciated.
>
> Thank you,
> tp 


0
Reply TedMi 11/28/2009 3:36:06 PM


1 Replies
1183 Views

(page loaded in 0.05 seconds)

Similiar Articles:
















7/23/2012 9:23:39 AM


Reply: