Results 1 to 4 of 4
  1. #1
    snobordin8 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2013
    Posts
    2

    Lookup queried value in another table

    I have two tables of data. One table looks like this

    310110.111001 242
    310113.111001 500
    310110.111002 350
    310115.111002 475

    2nd table looks like this:

    111001 Cash in Bank
    111002 Cash in Transit

    In my query, I want it to pull out the 111001 piece from table 1, and look up the item in table 2. I currently query using the mid function to pull out the 111001. I don't know how to look that value up in the 2nd table, and return it to the same query.



    Output should look like this:
    310110.111001 111001 Cash in Bank 242
    310113.111001 111001 Cash in Bank 500
    310110.111002 111002 Cash in Transit 350
    310115.111002 111002 Cash in Transit 475

    Any ideas? Thanks.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    let's say your first table is called table1 and your second table is called table2
    Table1 has fields Field1, Field2
    Table2 had fields Field1a, Field2a

    Create this query:

    Code:
    Select Field1, Right(Field1,6) as Field1aCalc, Field2 FROM Table1
    Save it as query1

    This should give you a query that looks like:

    310110.111001 111001 242
    310113.111001 111001 500
    310110.111002 111002 350
    310115.111002 111002 475

    (I think your output is in error the last two should have a 111002 in their second column)

    now create a new query with QUERY1 as the base and link it to Table2 via the Field1aCalc to Field1a and dump in the field you want.

    Don't do this query with a dlookup function.

  3. #3
    snobordin8 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2013
    Posts
    2
    You're right, my output was in error. I updated it.

    I think what you describe will work for me, but I was hoping to do this all within one query. It only adds one more query to the database but I'm trying to keep this as simple as possible.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You can do it in one query without using dlookup functions as well it's a bit more complicated but the net effect is the same.

    Here's a link to an example:

    http://stackoverflow.com/questions/2...lect-statement

    It's harder to edit these select in select queries if you're not a SQL person.

    If you are looking for a purely visual cleaning of your database you can hide all your queries or some of them if you want to.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-13-2012, 03:01 PM
  2. Replies: 9
    Last Post: 02-24-2012, 05:12 AM
  3. Need a function to change queried text
    By rjohnson in forum Queries
    Replies: 2
    Last Post: 02-20-2012, 10:28 AM
  4. Add selection to queried combo box
    By davefrag in forum Forms
    Replies: 1
    Last Post: 01-18-2012, 04:26 PM
  5. Replies: 1
    Last Post: 07-15-2011, 11:00 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