Access Custom Query

I have 2 tables. The first contains potential customers with name, address and zip code fields and a SalesId field. The second table contains sales territories with SalesId, BeginningZip and EndingZip fields.

I need a query that will marry the 2 tables together and assign the SalesId value from the sales territories table to the customer's table where the zipcode falls in the beginning and ending zip ranges.  
Douglas CummingsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
After backing up your database, try:

UPDATE table1
SET SalesID = DLOOKUP("SalesID", "Table2", "[BeginningZip] <= '" & table1.ZipCode & "' AND [EndingZip] >= '" & table1.zipcode & "'")
Rey Obrero (Capricorn1)Commented:
update customers c, territory t
set c.salesid=dlookup("salesID", "t","[c].[zip] >=  [t].[beginnningZip]  and  [c].[zip] <=[t].[endingzip])
Select * from customerTable a,salesTable b
where a.SalesId=b.SalesId and (a.zipcode>=b.BeginningZip and a.zipcode<=b.EndingZip);

Your current tables:
10 Holiday Gifts Perfect for Your Favorite Geeks

Still have some holiday shopping to do for the geeks in your life? While toys, clothing, games, and gift cards are still viable options for your friends and family, there’s more reason than ever to consider gadgets and software.

Douglas CummingsAuthor Commented:
Thanks for getting back to me so quickly.

Fyed, I tried your suggestion, but it didn't work. It actually deleted values that already existed in the SalesId field.

Capricorn1, I get an error message when I attempted to use your suggestion, that being "Unknown".

Here is my SQL statement. Perhaps I entered something incorrectly.

UPDATE 16263A2 AS C, dbo_tblSalesTerritories AS T SET C.SalesId = DLookUp("SalesId","T","[C].[Czip] >= [T].[BeginningZip] and [C].[Czip] <= [T].[EndingZip]");
Rey Obrero (Capricorn1)Commented:

UPDATE [16263A2] AS C, [dbo_tblSalesTerritories] AS T SET C.SalesId = DLookUp("SalesId","T","[C].[Czip] >= [T].[BeginningZip] and [C].[Czip] <= [T].[EndingZip]");
Douglas CummingsAuthor Commented:
Same result - "Unknown" error message.
Rey Obrero (Capricorn1)Commented:

UPDATE [16263A2] AS C, [dbo_tblSalesTerritories] AS T SET C.SalesId = " & DLookUp("SalesId","T","[C].[Czip] >= [T].[BeginningZip] and [C].[Czip] <= [T].[EndingZip]");
Douglas CummingsAuthor Commented:
I get a syntax error message.
Rey Obrero (Capricorn1)Commented:
try this

UPDATE [16263A2] AS C, dbo_tblSalesTerritories AS T
SET C.SalesID = [T].[SalesId]
WHERE C.Czip>=[T].[BeginningZip] AND C.Czip<=[T].[EndingZip]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Douglas CummingsAuthor Commented:

It worked like a charm. Thanks for the help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.