Solved

DSum Multiple Criteria

Posted on 2013-06-07
13
493 Views
Last Modified: 2013-06-07
I'm trying to create a DSum that uses 2 different criterias. I have one already set up and it works fine but I need to add another that references a control on my main form, not the subform where the DSum is. I tried just referencing the control on the form in the query criteria but I get the NAME# error. So I'm guessing I need to add this to the criteria of the DSum formula. Here's the code that I have so far without the second criteria:

DSum("fqtyrecv","qryPOHistory","Format([fdaterecv],'mmm-yy')='" & Format([Forms]![sfrmPurchaseAnalysisPOHisto

Open in new window


I need to add the criteria that uses the "fpartno" in the qryPOHistory and it needs to equal the cbofpartno on my frmPurchasingAnalysis1 form. How can I add that to the DSum formula? And why if I just put this "[Forms]![frmPurchasingAnalysis1]![cbofpartno]" in the criteria of the query itself do I get the NAME# error?
0
Comment
Question by:Lawrence Salvucci
  • 6
  • 6
13 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39228975
I cannot read the full code line.

/gustav
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39228981
=DSum("fqtyrecv","qryPOHistory",
"Format([fdaterecv],'mmm-yy')='" & 
Format([Forms]![sfrmPurchaseAnalysisPOHistory]![txtMonth1],'mmm-yy') & "'")

Open in new window

0
 
LVL 84
ID: 39229001
Your code segment is not complete, but if you want to add a new criteria, you'd do something like this:

DSum("fqtyrecv","qryPOHistory","Format([fdaterecv],'mmm-yy')='" & Format([Forms]![sfrmPurchaseAnalysisPOHistory].SomeControl & "' AND fPartNo='" & Forms!frmPurchasingAnalysis1.cbofPartNo & "'")

Note too that if you're dealing with Text values, you need to enclose them in single quotes or double quotes, as you've done with the fdaterecv value.
why if I just put this "[Forms]![frmPurchasingAnalysis1]![cbofpartno]" in the criteria of the query itself do I get the NAME# error?
That's hard to say without seeing your project, but in general the error means Access can't find that control. If you're using frmPurchasingAnalysis1 as a Subform, then you'd have to refer to it like this:

Forms!FormWithTheSubformCONTROL.NameOfTheSubformCONTROL.NameOfYourControl

Note "NameOfTheSubformCONTROL" - this may or may not be the same the form you're using as a Subform, so be sure to get that right.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39229008
Then it could be:
=DSum("fqtyrecv","qryPOHistory",
"Format([fdaterecv],'mmm-yy')='" & 
Format([Forms]![sfrmPurchaseAnalysisPOHistory]![txtMonth1],'mmm-yy') & "' And fpartno = " & [Forms]![sfrmPurchaseAnalysisPOHistory].[Parent]![cbofpartno] & "")
 

Open in new window


Of course, if fpartno is a string, single quotes must be wrapped around the value as for the first expression.

/gustav
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39229039
Still getting the #NAME? error message. The frmPurchaseAnalysis1 is the parent form and sfrmPurchasingAnalysisPOHistory is the subform where the DSum is. When the users select a part no from the cbofpartno then that's when it should fire the DSum on the subform but it's still not working. Here's what I have for the formula:


=DSum("fqtyrecv","qryPOHistory","Format([fdaterecv],'mmm-yy')='" & 
Format([Forms]![sfrmPurchaseAnalysisPOHistory]![txtMonth1],'mmm-yy') & 
"' And fpartno = " & [Forms]![sfrmPurchaseAnalysisPOHistory].[Parent]![cbofpartno] & "")

Open in new window

0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39229083
How about this simplified:
=DSum("fqtyrecv","qryPOHistory","Format([fdaterecv],'mmm-yy')='" & 
Format([txtMonth1],'mmm-yy') & 
"' And fpartno = " & [Forms]![frmPurchaseAnalysis1]![cbofpartno] & "")

Open in new window

/gustav
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39229151
Still not working. When I take out the second criteria it works fine. But once I add the fpartno criteria portion is when I still get the #NAME?. The fpartno is a text value if that makes any difference. I would post an example but my tables are linked to my SQL Database tables.
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39229224
If text value, single quotes must be applied:
=DSum("fqtyrecv","qryPOHistory","Format([fdaterecv],'mmm-yy')='" & 
Format([txtMonth1],'mmm-yy') & 
"' And fpartno = '" & [Forms]![frmPurchaseAnalysis1]![cbofpartno] & "'")

Open in new window


If you open the form and run this in the debug window, what do you see:

? [Forms]![frmPurchaseAnalysis1]![cbofpartno]

/gustav
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39229241
When I run that in the debug window I get "510125", which is the value in the cbofpartno.

Now when I changed the formula to your latest version I'm getting a flashing #ERROR
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39229245
Scratch that. I typed something wrong in your latest code. It's working now.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39229256
Great!

/gustav
0
 
LVL 1

Author Closing Comment

by:Lawrence Salvucci
ID: 39229263
Thanks for all your help! I greatly appreciate it!!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39229269
You are welcome!

/gustav
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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 …

744 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

11 Experts available now in Live!

Get 1:1 Help Now