Access lookup on partial string

Posted on 2013-10-30
Last Modified: 2014-04-10
Using Access '07...long time since I've been in Access...I need to do the equivalent of the following from Excel:

use the left 4 characters in a field to go to a table that has 5 versions of those 4 characters, and bring back into the table from which I'm looking, the value in the second field of the lookup table.

Basically, I have a table with a long list of account information (chart of accounts from accounting department).  The start of each account is "10-x" (with 'x' being anything from 4 to 8).  Depending on the 'x', it is either a 'revenue'/'expense'/etc. account type.  I am going to be taking the results of this out of Access and dumping to Excel, for pivoting.  I need that 'account type' designation to come across in the results.  In Excel, I'd simply do a vlookup(left(CELL,4),SHORT_TABLE_WITH_LOOKUP_VALUES,2,false), and I'd have my answer.  Don't know how to replicate that in Access, and can't seem to find the right online searches for answers.
Question by:txrussianguy
  • 4
  • 3
LVL 61

Expert Comment

ID: 39613496
This is aircode, and you'll have to replace table and field names to reflect those in your actual database.

You can do what you are describing by joining your main table with your lookup table in a query:

SELECT MainTable.*, LEFT(MainTable.Account, 4) AS AccountPrefix, LookupTable.AccountTypeDesignation
FROM MainTable INNER JOIN  LookupTable
ON LEFT(MainTable.Account, 4) = LookupTable.AccountTypeAbbreviation

Open in new window


Author Comment

ID: 39614204
Thanks for this...again, being a bit of a "re-" newbie, I'm lacking the overall context of how this would be used.  Am i putting this as a standalone query, or is this some sort of calculated field formula?  In other words, at which step would I be able to use these results?  What I ultimately am doing is pulling together the following, into a pivottable (for sharing reasons, may have to be done in Excel, though I see now I can in '07 Acc also do one):

Budget listing
Actual listing
This lookup of account type (to use as a filter in my pivot for selecting which portions of above two I want to see)
Some more looked up information from a "project id" table, which gives me certain characteristics of the project id's that are in the budget and actual information

So basically...where is this query coming into play?
LVL 61

Expert Comment

ID: 39614227
My suggestion was for a standalone query, to demonstrate the concept.  You can use the query as is and apply the output as needed, or apply the concept in your own context.

Even with your explanation your application is not completely clear so it is hard to provide a more specific answer.  If you are able to post a sample database, it might help.
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.


Author Comment

ID: 39614321
Thanks for the offer to teach me how to fish.  Attached is a completely stripped down version.  What I'm after is the ability to pivot with the information from Acct Type of "Account Lookup" table, married with the information from budget table...and then there will be a "Project ID" table, which gives info that is based on "Project #", as well as an 'actual' table, structured exactly like the budget table, but with "actual" in the "Act/Bud" column.

Hope it makes more sense now with a sample.

Thanks again.  Refreshing to have a network of folks that are a) obviously pro's, and b) so responsive.
LVL 61

Expert Comment

ID: 39615143
Hmm... still not clear.

Can you post a spreadsheet or similar visually showing what your expected output would be... using the tables and data in the sample.

(For the purpose of this question, lets focus on a single topic/query/output goal)

Author Comment

ID: 39615494
Attached is the very small snapshot.  For a column like 'E' in "IS 11", I don't want to have to populate it with "revenue", "expense", etc.  I want it to know what it's supposed to be.  The data output I get is A-D, so I'm trying to figure out how to get to my pivotable summary table (which has all elements), but with an efficient DB, which doesn't have to actually enter information over and over, but rather does a reference check against tables like "CoA" in this sheet (and project list, and so forth).

Hope now it's finally clearer than dark mud.
LVL 61

Accepted Solution

mbizup earned 500 total points
ID: 39615760
Okay - I think I understand what you are asking, and it is pretty much what I suggested earlier.

Look at the query qryBudget13.  That can be used for reporting purposes.

Then look at frmBudget13 (the form).  That is used for entering data.  You don't need, and shouldn't have lookup fields like account type in your tables... data like that can be looked up on an as-needed basis.

The form is one way to enter data such as the Account Number and have a form automatically display (but not store) the account type during data entry.  The right most textbox displays the account type using a DLookup function call (very similar to your VLookup):

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question