Go Premium for a chance to win a PS4. Enter to Win


Access lookup on partial string

Posted on 2013-10-30
Medium Priority
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


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 2000 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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

963 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