A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using a field name as variable in a query



 
 
Thread Tools Display Modes
  #1  
Old November 28th, 2009, 01:51 PM posted to microsoft.public.access.queries
titlepusher
external usenet poster
 
Posts: 12
Default Using a field name as variable in a query

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
  #2  
Old November 28th, 2009, 03:36 PM posted to microsoft.public.access.queries
Tedmi
external usenet poster
 
Posts: 141
Default Using a field name as variable in a query

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" wrote in message
...
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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:02 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.