Solved Converting a Concatenated VLookup from Excel to Access (1 Viewer)

RobertC004

New member
Local time
Today, 06:33
Joined
Mar 28, 2020
Messages
2
Hello!

I'm new to this forum... but have found a lot of answers to questions in the past. I'm pretty well versed in Excel, but Access stumps me a bit, at times.

I have a .txt file that gets refreshed each week. In the front end DB, we run queries, which then pushes the synthesized data to a BackEnd DB.

There is a lookup table in Access that looks a lot like the one below:

Type CodeType TextReason CodeReason Text
XGChange of PositionX5Promotion-Regular
XQTransferX5Transfer Back
XGChange of PositionX6Promotion-Growth
XQTransferX6Transfer - Line of Business

In the report that spits out to .txt file, I would get the following data:
Type CodeType TextReason CodeReason Text
XGChange of PositionX5<blank>
XQTransferX5<blank>
XGChange of PositionX6<blank>
XQTransferX6<blank>

In the formatted report, at the end, I need to have all four columns populated.

How could I, in query form, get Access to "fill in" the "Reason Text" column?

It's not a straight up join, as the Reason Text is dependent on the combination of Type Code & Reason Code.

I was thinking about doing an Update Query in two steps... or possibly splitting the Lookup Table into two... but I'm thinking there might be an easier solution.

In Excel, I would likely do a VLookup on the Concatenation of the Two Codes... but i'm not even sure that's a solution in Access.

Any suggestions?

Thank you!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:33
Joined
May 7, 2009
Messages
19,230
say A=lookup table
and B the raw table
Code:
select B.*, A.[Reason Text]
    from B Left Join A
          On B.[type code]=A.[type code]
          And B.[type text]=A.[type text]
          And B.[reason code]=A.[reason code];
 

namliam

The Mailman - AWF VIP
Local time
Today, 12:33
Joined
Aug 11, 2003
Messages
11,695
Yeap a simple join, except your using multiple columns to join on which isnt a problem if that is te requirement and a common one at that.
Many joines join the two tables on multiple columns

As for the suggestion @angelgp gave, joining on a "text" field is generaly a bad idea, as you descibe the two code fields will suffice.
Code:
select B.*, A.[Reason Text]
from B 
Left Join A
          On B.[type code]=A.[type code]
          And B.[reason code]=A.[reason code];

If you are using the query designer in access simply add you two tables, then drag both code fields on top of the other 1 by 1.

Good luck
 

RobertC004

New member
Local time
Today, 06:33
Joined
Mar 28, 2020
Messages
2
Awesome... thank you, both. I was trying to do other joins... and the direct join on both fields was exactly what i needed. Thanks!
 

Users who are viewing this thread

Top Bottom