IIF question

G

Guest

Hi,
I have a table with an address field that I used a formula to trim down to
retrieve just ZIP codes. I have another table that lists all ZIP codes and
their associated cities. I want to be able to run a query that will convert
all of the zip codes in the first table into city names. Could you tell me
how to do this? I tried the following:
IIF([Expr5]=[ZipCode],[City],"")
as well as:
IIF("[Expr5]"="[ZipCode]","[City]","")
Note: Expr5 is the calculation from the first query that trimmed down
addresses to Zip codes. ZipCode and City are fields from the table that lists
all zips and cities.
If you know what I'm doing wrong please help,
Thanks
 
G

Guest

Maybe an IIF statement isn't the answer. I've used calculated columns before
using DLookup:
CityColumn: DLookup("City","TableWithCityAndZipInfo","ZipCode=" & Expr5)
Square brackets only necessary if there are spaces in field or table names.
 
J

John Spencer

Create a new query.

Add in the query that has the calculated zip code.
Add the table with the zip codes and cities
Join the two on the calculated zip code (expr5) and the zip code in the
table.
 
G

Guest

That sounds like a really good idea. However, I am now getting a "data
mismatch in criteria type" error. I think this is possibly due to something I
found about the Dlookup function which said that any field name in the
criteria has to be in the domain, but my Expr5 comes from a different table
than the City and ZipCode fields do. By the way, the
"TableWithCityAndZipInfo" table is called "ZIPList".
Any suggestions?
Thanks

rpurosky said:
Maybe an IIF statement isn't the answer. I've used calculated columns before
using DLookup:
CityColumn: DLookup("City","TableWithCityAndZipInfo","ZipCode=" & Expr5)
Square brackets only necessary if there are spaces in field or table names.

thatmoodieguy said:
Hi,
I have a table with an address field that I used a formula to trim down to
retrieve just ZIP codes. I have another table that lists all ZIP codes and
their associated cities. I want to be able to run a query that will convert
all of the zip codes in the first table into city names. Could you tell me
how to do this? I tried the following:
IIF([Expr5]=[ZipCode],[City],"")
as well as:
IIF("[Expr5]"="[ZipCode]","[City]","")
Note: Expr5 is the calculation from the first query that trimmed down
addresses to Zip codes. ZipCode and City are fields from the table that lists
all zips and cities.
If you know what I'm doing wrong please help,
Thanks
 

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