Results 1 to 4 of 4
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038

    DLookup results in #Error *for 1st record only*

    Query "qry_SampleData" includes two expressions:



    Code:
    1. EOM_BALANCE: (Select Sum(T.CHARGE) From tbl_SampleData As T Where  T.ID<=tbl_SampleData.ID;)+((Select Sum(T.CHARGE) From tbl_SampleData As T Where  T.ID<=tbl_SampleData.ID;)*0.065/12)
    2. BALANCE: Val(DLookUp("[EOM_BALANCE]","qry_SampleData","[ID]=" & [ID]-1))
    The EOM balance is calculated correctly. However, the BALANCE expression results in an "#Error" **for the 1st record** (only).

    My questions:
    a. Given there's no "previous record" for the 1st record, how can the BALANCE expression be tweaked so that it would pass the [CHARGE] field (i.e., $5,000 in this case) into the 1st record and then continues with the EOM balance calculation from the previous record (for all remaining records)?
    b. How can the expression be limited to only 2 decimals.

    Thanks,
    EEH
    Attached Thumbnails Attached Thumbnails Query.JPG  
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Wrap the DLookup() in the Nz() function. I suspect the Val() function is throwing an error on the Null being returned.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    pbaldy - thank you... the following appears to work.

    Code:
    BALANCE: Val(Nz(DLookUp("[EOM_BALANCE]","qry_SampleData","[ID]=" & [ID]-1),[CHARGE]))
    Much obliged.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Unexpected results with DLookup
    By GraeagleBill in forum Programming
    Replies: 9
    Last Post: 02-12-2021, 04:48 PM
  2. DLookUp Error When Updating Record It Calls
    By spartyon in forum Programming
    Replies: 8
    Last Post: 07-03-2019, 02:22 PM
  3. dlookup to narrow search results
    By blappy347 in forum Programming
    Replies: 2
    Last Post: 03-29-2013, 02:25 PM
  4. Replies: 2
    Last Post: 01-04-2013, 09:04 PM
  5. DLookup not getting results
    By Huddle in forum Access
    Replies: 15
    Last Post: 02-10-2012, 01:02 PM

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