Hey,
This is very complex and there is probably a better way than a DLookup but I dont know how. I am not getting the correct results with what I have. This is Access XP by the way. I have two tables of course. The first is tblList which I am using in the query. I need to look up the Territory from tblTerritories according to the zip code in tblList.
tblList has
OfficeCode(TX-1) and Zip(79302) that I will use for Dlookup
tblTerritories has
OfficeCode, Territory, StartTerritory and EndTerritory
TX-1 North 790 795
TX-1 South 769 769
TX-1 West 770 789
but the kicker is sometimes a five digit number
TX-5 North 79720 79935
If the Office Codes match then I want the correct Territory that is or falls in between StartTerritory and EndTerritory. I tried to use this below but only get North for all records.
Terrirory: DLookUp("[TerrName]","tblTerritories","[tblTerritories]![OfficeCode] = [OfficeCode]" And IIf(Len([tblTerritories]![StartTerritory]=5),[Zip]>=[tblTerritories]![StartTerritory] And [Zip]<=[tblTerritories]![EndTerritory],IIf(Len([tblTerritories]![StartTerritory]=3),Left([Zip],3)>=[tblTerritories]![StartTerritory] And Left([Zip],3)<=[tblTerritories]![EndTerritory],[tblTerritories]![StartTerritory]=0)))
IF there is an easier way, please let me know. Im sure this will make the report slow. Thanks Lisa
This is very complex and there is probably a better way than a DLookup but I dont know how. I am not getting the correct results with what I have. This is Access XP by the way. I have two tables of course. The first is tblList which I am using in the query. I need to look up the Territory from tblTerritories according to the zip code in tblList.
tblList has
OfficeCode(TX-1) and Zip(79302) that I will use for Dlookup
tblTerritories has
OfficeCode, Territory, StartTerritory and EndTerritory
TX-1 North 790 795
TX-1 South 769 769
TX-1 West 770 789
but the kicker is sometimes a five digit number
TX-5 North 79720 79935
If the Office Codes match then I want the correct Territory that is or falls in between StartTerritory and EndTerritory. I tried to use this below but only get North for all records.
Terrirory: DLookUp("[TerrName]","tblTerritories","[tblTerritories]![OfficeCode] = [OfficeCode]" And IIf(Len([tblTerritories]![StartTerritory]=5),[Zip]>=[tblTerritories]![StartTerritory] And [Zip]<=[tblTerritories]![EndTerritory],IIf(Len([tblTerritories]![StartTerritory]=3),Left([Zip],3)>=[tblTerritories]![StartTerritory] And Left([Zip],3)<=[tblTerritories]![EndTerritory],[tblTerritories]![StartTerritory]=0)))
IF there is an easier way, please let me know. Im sure this will make the report slow. Thanks Lisa