View Single Post
  #2  
Old June 1st, 2010, 08:40 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Query--using Access 2007

One method.

SELECT tblCompanies.*, tblAddress
FROM tblCompanies INNER JOIN tblAddress
ON tblCompanies.CompanyID = tblAddress.CompanyID
WHERE tblAddress.TypeOfAddressID =
(SELECT Min(Temp.TypeOfAddressID)
FROM tblAddress as TEMP
WHERE Temp.CompanyID = tblAddress.CompanyID)

If that is too slow then post back for an alternative query. When you do tell
us the names of the key fields and the names of the tables involved.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

lmcc via AccessMonster.com wrote:
I have a tblAddress table with a lookup field called TypeofAddressID.

A company may have many addresses with different TypeofAddressID—such as 1 =
Business, 2 = Mailstop, 3 = PO Box, and so on.

I need to pull out TypeofAddressID # 1. Then if a 1 is not available, give
me the type that is (which may be the PO address or Mailstop).

I tried DLookup, Xor, and IIf([TypeofAddressID]=1, 1, IIf([TypeofAddressID]=2,
2, IIf([TypeofAddressID]=3, 3, 4))), but it is listing all addresses per
company instead of either or.

Any suggestions?