Solved

DSum not working correctly

Posted on 2011-03-11
9
333 Views
Last Modified: 2013-11-05
I am using DSum as a default value on a form but am not getting the correct result.  Probably because I have " and ' marks wrong.  Can someone help?  Here my code:

=DSum("Qty","tblProdInventory","'Style = #10 Product' & 'CompanyName = frmProjectDetail!txtCompany'")

--Steve
0
Comment
Question by:SteveL13
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 84
ID: 35111836
=DSum("Qty","tblProdInventory","Style = '#10 Product' AND CompanyName ='" &  frmProjectDetail!txtCompany & "'")
0
 
LVL 84
ID: 35111850
Sorry, posted too quickly:

Also, understand that a Default value ONLY impacts New records. It will have absolutely no impact on Existing records.

And, in your case, if there is no value in txtCompany, or if txtCompany is on the same Form where you're running this, then you will almost certainly run into issues with it.
0
 

Author Comment

by:SteveL13
ID: 35111880
I pasted this in the default value and am getting a #Name? result.   ??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:MINDSUPERB
ID: 35111893
Try this one

=DSum("[Qty]","tblProdInventory","[Style] = '#10 Product' And  [CompanyName] =' " & Forms!frmProjectDetail!txtCompany & "'")

Sincerely,
Ed
0
 

Author Comment

by:SteveL13
ID: 35111938
Tried that one and now I get no result in the field.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 35111992
No leading space:

=DSum("Qty","tblProdInventory","Style = '#10 Product' And CompanyName = '" & frmProjectDetail!txtCompany & "'")

/gustav
0
 
LVL 10

Expert Comment

by:conagraman
ID: 35112152
i = DSum("Qty", "tblProdInventory", "Style = '#10 Product' And CompanyName = 'frmProjectDetail!txtCompany'")
0
 
LVL 10

Expert Comment

by:conagraman
ID: 35112176
cactus_data:

my bad. i didnt refresh before i saw your comment
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 35112361
<Tried that one and now I get no result in the field.>

Are you absolutely sure that your DSum will return a value? That is, are you sure this is at least one positive value in the Qty field for the Criteria you've entered? That is, there is at least one value in that field where your Style is "#10 Product" and the CompanyName is the value in Forms("frmProjectDetail").txtCompany?

Does the CompanyName contain any odd names, like O'Brian? If so, you'll need to "escape" those:

=DSum("Qty","tblProdInventory","Style = '#10 Product' AND CompanyName ='" &  Replace(Forms("frmProjectDetail").txtCompany, "'", "''") & "'")
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My Do While is Not Producing Anything 15 87
microsoft Access form help 5 15
Missing DLL in Access 2010 11 30
Reoccurring Access Query 24 47
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 …
Familiarize people with the process of utilizing SQL Server views 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 Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

734 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