Solved

Error in DSum textbox while on new record

Posted on 2008-10-30
5
336 Views
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.
0
Comment
Question by:cers4686
[X]
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
5 Comments
 
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")
0
 
LVL 75

Accepted Solution

by:
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)

mx
0
 
LVL 57
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)
    
AvoidError_Exit:
    Exit Function
 
AvoidError_Error:
    AvoidError = varReplaceWith
    Resume AvoidError_Exit
    
End Function

Open in new window

0
 

Author Closing Comment

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

mx
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

730 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