Results 1 to 6 of 6
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Make Form Control Blank if Error

    I have an unbound form control (From Control A) that is contains a dlookup formula. The dlookup formula references a bound form control (Form Control B). When I open the form to a new record, Control Form A returns an error because Form Control B is null. Can I program Form Control A so that it returns blank instead of an error while Form Control B is null?



    I have been searching for a solution for over an hour to no avail.

    First, I tried NZ, because I understand NZ has a built-in "Iferror" equivalent.
    Code:
    NZ([Form Control A formula), "")
    But that returns an #error.

    I also tried a combination of IIF and Not IsError.

    Code:
    IIF(Not IsError([Form Control A formula], [Form Control A formula], "")
    That also returns in #error. I would greatly appreciate any advice.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    IIf() in Access requires all parts of expression can be evaluated, so since your DLookup can't, the IIf() itself returns error.

    Nz() is not testing for error, it is testing for Null and returns alternate value if Null is read. Since DLookup returns error, not Null, Nz() fails.

    IsError doesn't do what you think and won't work in an expression like that. Even if it did, your expression is missing a paren. Unfortunately, MS documentation for IsError seems to be less than clear on how to use. This discussion helped me understand better https://stackoverflow.com/questions/...eturning-error

    Wrap reference to control B with Nz().

    Show the DLookup expression.
    Last edited by June7; 04-05-2025 at 10:24 AM.
    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
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Fairly common topic:
    https://answers.microsoft.com/en-us/...a-16f083d440a4
    https://groups.google.com/g/comp.dat...4M56GaMs?pli=1
    Wrapping the control B in Nz() should fix it.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  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,652
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    show us the formula of the DLookup.

  6. #6
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Thank you all for your responses. I attempted to multiquote everyone but couldn't get it to work. NZ worked liked a charm. Thank you all!

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

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2018, 04:06 PM
  2. Replies: 3
    Last Post: 11-30-2016, 07:18 PM
  3. Replies: 4
    Last Post: 02-18-2016, 12:06 PM
  4. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  5. Replies: 1
    Last Post: 09-05-2008, 12:07 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