Solved

DSum Multiple Criteria

Posted on 2013-06-07
13
502 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 50

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

 
LVL 50

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 50

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 50

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 50

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 50

Expert Comment

by:Gustav Brock
ID: 39229269
You are welcome!

/gustav
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net dbnull syntax 1 58
GA Ribbon creator 9 63
Access 2003, find all instances of database ODBC 3 50
Turning An Access Query Data from horizontal to vertical 14 29
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

738 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