Solved

DSum not working correctly

Posted on 2011-03-11
9
327 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
  • 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now