Error in DSum textbox while on new record

Posted on 2008-10-30
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 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

696 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