Results 1 to 3 of 3
  1. #1
    TommyT77 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2013
    Posts
    2

    Specifing a variable field in a Dlookup function in a query

    Table PPM, collects information from a user, including fields called “Week No” and “Day”.

    Week No Day Description of Work
    1 Saturday Digging holes
    1 Tuesday Filling in holes
    2 Sunday Digging more holes


    I have another table called “Rail Weeks”, which is used to lookup dates (as strings and NOT dates). The primary field is “Week No” and the rest of the fields are days of the week:

    Week No Saturday Sunday Monday Tuesday Wednesday Thursday Friday
    1 01-01-13 02-01-13 03-01-13 04-01-13 05-01-13 06-01-13 07-01-13
    2 08-01-13 09-01-13 10-01-13

    I want the returned query to show all the fields in the “PPM” table plus the resolved date from the “Rail Weeks” table.

    Week No Day Description of Work Date (Lookup from Railways)
    1 Saturday Digging holes 01-01-13
    1 Tuesday Filling in holes 04-01-13
    2 Sunday Digging more holes 09-01-13

    I’ve been looking at the Dlookup function, and I’ve managed to get it to work as an expression in a query, but it only returns me dates for a single set field from the “rail weeks” table (day of the week), for each record specified by the Week No in the “PPM” table. For example the below expression will return dates on Monday, for each week entered by a user in the PPM table but takes no account of what day is entered into the PPM table.

    Expr1: DLookUp("[Monday]","[Rail Weeks]","[Wk No Data] =" & [PPM]![Week No])

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not seeing a field named [Wk No Data].

    Try:

    DLookup([Day], "[Rail Weeks]", "[Week No]=" & [Week No])
    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.

  3. #3
    TommyT77 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2013
    Posts
    2
    Thanks very much June7. It's amazing how easy it is to over complicate something. I've been trying all sorts complicated VBA to solve this problem - Many thanks.

    By the way, the field [Wk No Data] should have read [Week No] from the rail weeks table - not that is matters. Problem solved.

    Thanks. TommyT

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

Similar Threads

  1. Dlookup, selecting with variable
    By cihan in forum Programming
    Replies: 6
    Last Post: 03-09-2012, 06:06 AM
  2. Newbie. How do I use DLookup with a variable please?
    By graffiti in forum Programming
    Replies: 2
    Last Post: 12-12-2011, 08:59 AM
  3. Use a variable in a DLOOKUP?
    By leftylee in forum Forms
    Replies: 9
    Last Post: 07-27-2011, 02:00 PM
  4. Dlookup in query using Global variable
    By newwales in forum Access
    Replies: 1
    Last Post: 06-03-2011, 03:47 PM
  5. Help Using Variable in DLookup Statement
    By bcmarshall in forum Access
    Replies: 9
    Last Post: 12-02-2010, 12:44 AM

Tags for this Thread

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