Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Oct 2014
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Access 2010 DLookup - Table name is a variable value

    Hi, I can't find an answer to this anywhere.

    I have a situation where the table name is stored as a text value in a table and this can be different for each record. The Field that contains the table name is "PREV_TABLE" and is stored in a table "TBL_PAYMENT_DUE".

    I have tried DLookup("[ACCT_NO]", "TBL_PAYMENT_DUE.PREV_TABLE" , "ID=" &TBL_PAYMENT_DUE.ID) which returns #Error.

    If I replace the table name with one of the text values in PREV_TABLE it works fine for those records that the fixed table name applies to.

    What is the correct syntax?

    Thanks

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    I'm not sure of the context in which you are using it (in a query, in code, etc.). But this is most likely what you need (notice I removed the quotes around the tablename:

    DLookup("[ACCT_NO]", TBL_PAYMENT_DUE.PREV_TABLE , "ID=" & TBL_PAYMENT_DUE.ID)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. The Following User Says Thank You to MarkLiquorman For This Useful Post:

    mickelb (2014-11-29)

  4. #3
    New Lounger
    Join Date
    Oct 2014
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Many thanks - so basic and so simple I hadn't tried this! It is within a query at the moment but may well end up in VBA.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •