Error in DSum textbox while on new record

Posted on 2008-10-30
Medium Priority
Last Modified: 2013-11-28
I have a form in datasheet view where the user chooses a few items to buy. I then have a textbox that calculates the total price of those items. The control source of the Totals textbox is as follows:

=DSum("([Price]+([Price]*[Adjust]))*[Quantity]","QuoteDetails","[QuoteID] =" & [QuoteID] & "AND [Optional]=0")

The problem is that when I am on the form and the cursor is in one of the fields for a new record, the Totals textbox shows #Error. Why is this happening and what can I do to prevent this #Error from showing up when the user is selecting a new item?
Thank you for your help.
Question by:cers4686
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22844168

=DSum("(nz([Price],0)+(nz([Price],0)*nz([Adjust],0)))*nz([Quantity],0)","QuoteDetails","[QuoteID] =" & [QuoteID] & " AND [Optional]=0")
LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 22844187

try this

=IIF(Not IsNull([YourPrimaryKeyFieldName],   DSum("([Price]+([Price]*[Adjust]))*[Quantity]","QuoteDetails","[QuoteID] =" & [QuoteID] & "AND [Optional]=0") , Null)

Replace YourPrimaryKeyFieldName  with the primary key field name - or some field you can guarantee will not be Null IF if you are on a record (not on a New record)

LVL 58
ID: 22844438

Or use the function attached like so:

=AvoidError(DSum("([Price]+([Price]*[Adjust]))*[Quantity]","QuoteDetails","[QuoteID] =" & [QuoteID] & "AND [Optional]=0"))

Function AvoidError(n As Variant, varReplaceWith As Variant)
    On Error GoTo AvoidError_Error
    AvoidError = Nz(n, varReplaceWith)
    Exit Function
    AvoidError = varReplaceWith
    Resume AvoidError_Exit
End Function

Open in new window


Author Closing Comment

ID: 31511803
brilliant! thank you!
LVL 75
ID: 22844596
You are welcome ...


Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question