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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.


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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

689 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