Solved

DSum Multiple Criteria

Posted on 2013-06-07
13
498 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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
 
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 VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
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…

810 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