Results 1 to 9 of 9
  1. #1
    oldlearner is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2015
    Posts
    31

    Access equivalent of excel Vlookup


    Hi all. I have 2 tables. Table 1 has 2 fields PostCode and Area. Table 2 also has 2 fields, postcode2 and Area2 which are populated with data. When I type a post code into table 1, I want it to look at table 2 to match the post code in column 1 and return the value from Area2 into the Area field in table 1. This is achieved in Excel with a Vlookup but I would like to know how to achieve this in access. Many thanks for any assistance anyone can give

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    why do you need 2 tables with matching data?
    This is normally unnecessary in a database where one principle is that data is stored once and used in multiple ways as necessary.

    If you really must do this, you would use an update query
    Join the 2 tables using the Postcode field.
    Add the table1 Area field to the query and in the Update To row enter Table2.Area.
    Run the query to synchronise all matching Area fields in one go.

    Another thing - you can obtain all postcode data for free for most countries.
    If you want UK postcode data I can supply this for you or tell you places to download it
    Last edited by isladogs; 06-16-2019 at 12:22 PM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does this fit the situation?

    http://www.baldyweb.com/Autofill.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    oldlearner is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2015
    Posts
    31
    Not sure if I explained well enough, to clarify, Table 2 has 24932 records with Post codes and associated Ward areas listed in column 2. When I type a post code in table 1, I want it to look up the identical post code in table 2 and return the associated ward area from column 2 to the ward field In table 1. This is a common task in excel accomplished by using a Vlookup.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    That really doesn't help much.
    First you mentioned Area...now its Ward.

    Why would you type a postcode in table1 when you have the data in table2?

    You're probably wanting to use the DLookup function.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Also, most of us never let users work directly in tables or queries, only forms and reports. The link I posted would work in a form, and as Colin and my link state you would not normally save the area in table 1.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Another voice of reason, I hope.
    I presume Table1 has more than just those 2 fields.
    Don't save Table2 Area2 (ward) data into Table1. Build query that joins on the common PostCode fields to retrieve related data. This is a primary reason for using relational database.

    If you want to see the Ward next to PostCode on a form, options:

    1. pbaldy suggestion using a multi-column combobox for selecting PostCode, then textbox can reference combobox column by its index, index begins with 0: =[cbxPC].Column(1)

    2. include Table2 in form RecordSource (RIGHT JOIN) and bind textbox to Table2 Area2 and set Locked Yes and TabStop No

    3. DLookup() expression in textbox
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    oldlearner is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2015
    Posts
    31
    Thanks for all your comments, they are much appreciated. I was trying to reproduce a Vlookup procedure In access and as you have all noted I was barking up the wrong tree. As you rightly say it was a simple lookup and query to solve it. can you advise if I should index the post code field as there are over 25,000 post codes in it. Many Thanks

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    We were all glad to help.
    Yes - you should index any field used in searches. It will significantly speed up your searches
    even if you had e.g. the full UK postcode set of approx 2.6 million postcodes, indexing means it would still be near instantaneous
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-28-2017, 02:05 AM
  2. Replies: 4
    Last Post: 02-16-2017, 05:08 PM
  3. Excel MATCH formula and Access Equivalent
    By maeyks in forum Access
    Replies: 4
    Last Post: 03-14-2016, 05:31 AM
  4. Vlookup equivalent in Access
    By Eddie in forum Access
    Replies: 2
    Last Post: 04-01-2014, 09:43 AM
  5. Replies: 10
    Last Post: 08-29-2012, 06:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums