Results 1 to 13 of 13
  1. #1
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16

    VLOOKUP Alternative

    Hi there,

    I have a table containing a number of organisations. One of the fields on this table contains each organisation's postcode.

    There is also a second table containing a list of postcode districts and the name of a person whom that district is allocated / assigned to.

    Please can someone help me to automatically assign an individual from the district table to the organisation table. As the district allocations change, these changes should automatically update in the organisation table.



    The third table below shows my desired final result.

    Many thanks in advanced!

    ID Name Postcode
    1 Org1 AL10 8TU
    2 Org2 W1 8HA
    3 Org3 N10 69A

    District Allocated to
    W1 John
    N10 Bill
    AL10 John
    AL11 John
    AL12 John


    ID Name Postcode Allocation
    1 Org1 AL10 8TU John
    2 Org2 W1 8HA John
    3 Org3 N10 69A Bill

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    One way:

    Create a query on the first table which includes a calculated field to strip off the District from the Postcode.
    Then create a new query that joins the first query to the second table on the District fields, and returns the Fields that you want.

    Alternatively, you could use a DLOOKUP. See: https://www.techonthenet.com/access/...in/dlookup.php
    (you would just need to use a calculation to strip District off of Postcode here too).

  3. #3
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Provided your postcodes are properly formed you can do this in one query;
    Code:
    SELECT ID, Name, Postcode, AssignedTo 
    FROM Organisations , Allocations 
    WHERE District = Left([Postcode],Len([Postcode])-4) AND Postcode Is Not Null
    Caveats - Correctly formed postcodes, and your two tables are called Allocations and Organisations
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16

    Smile

    Quote Originally Posted by Minty View Post
    Provided your postcodes are properly formed you can do this in one query;
    Code:
    SELECT ID, Name, Postcode, AssignedTo 
    FROM Organisations , Allocations 
    WHERE District = Left([Postcode],Len([Postcode])-4) AND Postcode Is Not Null
    Caveats - Correctly formed postcodes, and your two tables are called Allocations and Organisations
    Thank you both for your responses - both look really useful.

    Minty - I like the idea of being able to run this all in a single query to eliminate the requirement for an additional field showing the first half of the postcode.

    I am quite new to Access so sorry for any stupid questions. Does this mean that my 'working table' would be the query or will this directly insert the names of the individuals on to the organisation table?

    Many thanks again!

  5. #5
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16
    Code:
    SELECT ID, Name, Postcode, AssignedTo 
    FROM Organisations , Allocations 
    WHERE District = Left([Postcode],Len([Postcode])-4) AND Postcode Is Not Null
    I guess I need to just convert this to an update query and run it every time the allocations change? Any ideas on how I can achieve this?

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Does this mean that my 'working table' would be the query or will this directly insert the names of the individuals on to the organisation table?
    I guess I need to just convert this to an update query and run it every time the allocations change? Any ideas on how I can achieve this?
    No! It is a violation of the rules of normalization to have table fields that are dependent upon other fields. It can undermine the dynamic nature of the database.

    Since the values can be gotten by the query above, there is no reason to store then back at the table level. A general rule of thumb is to never store a value that can be calculated easily on-the-fly.
    Pretty much anything that you would use a Table for (control source of Form, Report, or Export), you can use a Query for. So there should seldom be a reason to have to store it back at the Table level.
    (There are some execptions, like if you are creating a historical table to track the value of changing fields at a specific point in time).

  7. #7
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Joe's advice is spot on.

    By using the query as your source for the form or report, you never need worry about keeping things up to date.
    You are always using your tables current data.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16
    Hi both,

    Whilst I understand what you are saying, I cannot add additional information to records from a query table as it says 'This Recordset is not updateable'. The purpose of this exercise is to allow me to filter by an individual's name and THEN add notes to those records as required.

    Hopefully that makes sense. Do you have any futher recommendations?

    Thanks for all your helps so far.

    Kind regards,


    Dominic Muir

  9. #9
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Left join this query to the table you want to update in another query.

    That should give you and updatable record set.
    You can then display the Allocation Name, but make it so that it can't be edited.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16
    Hi Minty,

    That sounds like the perfect solution! Please can you explain how I would go about this? Sounds very complicated

  11. #11
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Do you have a small sample of your data and the form you are trying to use.
    If you can compact and repair it, then ZIP it (Change any personal data, dummy data is fine) and post it here it will be a 2 minute job to do then you can see.

    Alternatively, save the query above as qryAreaAlocations.

    Create a new query in the designer, add organisations table and qryAreaAlocations.

    Drag the ID field from tblOrganisations to the ID field in the query. It should join them with a line.
    double click the join line and select the option to show all the organisations and only the matching qry records.

    Pull all the Organisation fields into the qry output, and the Assigned to field from the qry .

    Try this query as your forms record source.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #12
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16
    Got it! Thanks again for all your help on this.

  13. #13
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You are welcome - good luck with your project.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Help with Excel vlookup alternative in Access
    By kozatchek in forum Access
    Replies: 2
    Last Post: 05-12-2017, 02:12 PM
  2. Sendkey alternative help
    By Madmax in forum Access
    Replies: 1
    Last Post: 04-10-2012, 10:46 AM
  3. Dlookup alternative
    By scotty22 in forum Queries
    Replies: 19
    Last Post: 10-26-2011, 06:20 AM
  4. alternative to autofeupdate
    By TheShabz in forum Programming
    Replies: 3
    Last Post: 07-19-2011, 11:38 AM
  5. Alternative to mapnetworkdrive?
    By dwcolt in forum Programming
    Replies: 1
    Last Post: 05-11-2011, 08:58 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