Results 1 to 7 of 7
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828

    Getting rid of #error in txt box

    Hello All,
    I have an unbound txtBoxes that has the following code in the control source, Unbound TxtBox, Currency Format

    Code:
    =Nz(DLookUp("AcctBalance","qryAccountBalance","AccountID=" & [CboToAccount].[Column](0)),0)
    And when CboToAccount is Empty or Null, then i get an #error in the txt box. What do i need to add to this to get rid of the #error?
    Thanks

  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,652
    Wrap the combo reference in the Nz() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Referencing Column(0) is probably just the value held by combobox, assuming BoundColumn is first field - so don't need the Column(0).

    If no selection has been made, the field is Null and AccountID=Null fails. So yes, the correct place to use Nz() is around the combobox reference.

    Now, if you want the textbox to show 0 instead of Null result of DLookup(), use Nz() also around DLookup() (as you are already).
    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.

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Thanks all,
    Just to be clear it should look like this?

    Code:
    =Nz(Nz(DLookUp)("AcctBalance","qryAccountBalance","AccountID=" & Nz([CboToAccount])),0)
    
    OR
    =Nz(Nz(DLookUp("AcctBalance","qryAccountBalance","AccountID=") & Nz([CboToAccount])),0)
    And this will give me a value of 0 (Which is what i seek) Correct if the combo is null or empty?
    Thanks
    Dave

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Not quite, and I would disambiguate the inner Nz():

    =Nz(DLookUp("AcctBalance","qryAccountBalance","Acc ountID=" & Nz([CboToAccount],0)),0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Thank you so much! I would have never guessed at that...
    I will mark solved then...
    Again,
    Thank you

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    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. Replies: 6
    Last Post: 02-03-2020, 07:09 PM
  2. Replies: 5
    Last Post: 07-15-2019, 10:20 AM
  3. Replies: 6
    Last Post: 03-17-2016, 02:10 PM
  4. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  5. Replies: 0
    Last Post: 07-16-2012, 05:42 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