Solved

DSum Multiple Criteria

Posted on 2013-06-07
13
504 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
[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
  • 6
  • 6
13 Comments
 
LVL 51

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 85
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 51

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 51

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
 
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 51

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 51

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 51

Expert Comment

by:Gustav Brock
ID: 39229269
You are welcome!

/gustav
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

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…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

628 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