Solved

DSum Criteria

Posted on 2014-11-24
9
153 Views
Last Modified: 2014-11-24
I have the following code in a control source for a form field.

=DSum("[QTY_ORDERED]","tblInventory","[PART_NO] = '" & [Forms]![frmParts]![txtPART_NO] & "'")

But I need to change it to include criteria like AND [TRNX_CODE} = "I" or "O"

I tried this but it doesn't work:

= DSum("[QTY_ORDERED]", "tblInventory", "[PART_NO] = '" & Forms![frmParts]![txtPART_NO] & "'" AND [TRNX_TYPE] = "'" I "'" OR "'"O"'"

What am I doing wrong?
0
Comment
Question by:SteveL13
  • 4
  • 3
  • 2
9 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40462975
Well, which is it [TRNX_CODE] or [TRNX_TYPE], it cannot be both.  Assuming it is [TRNX_TYPE], try:

= DSum("[QTY_ORDERED]", "tblInventory", "[PART_NO] = '" & Forms![frmParts]![txtPART_NO] & "' AND [TRNX_TYPE] = IN('I','O')")
0
 

Author Comment

by:SteveL13
ID: 40462991
It is TRNX_TYPE.    Sorry I mistyped.

I tried:

= DSum("[QTY_ORDERED]", "tblInventory", "[PART_NO] = '" & Forms![frmParts]![txtPART_NO] & "' AND [TRNX_TYPE] = IN('I','O')")

but get an #Error in the field.

If it matters TRNX_TYPE is a text field.
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40462995
try:

=DSum("[QTY_ORDERED]","tblInventory","[PART_NO] = '" & [Forms]![frmParts]![txtPART_NO] & "' AND [TRNX_CODE] in ('I','O')")

or

=DSum("[QTY_ORDERED]","tblInventory","[PART_NO] = '" & [Forms]![frmParts]![txtPART_NO] & "' AND (([TRNX_CODE]='I') OR [TRNX_CODE]='I'))")
0
 

Author Comment

by:SteveL13
ID: 40463006
This worked:

=DSum("[QTY_ORDERED]","tblInventory","[PART_NO] = '" & [Forms]![frmParts]![txtPART_NO] & "' AND [TRNX_CODE] in ('I','O')")
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 51

Expert Comment

by:HainKurt
ID: 40463007
i guess both should work...

except copy & paste issue ^^^ :)

=DSum("[QTY_ORDERED]","tblInventory","[PART_NO] = '" & [Forms]![frmParts]![txtPART_NO] & "' AND (([TRNX_CODE]='I') OR [TRNX_CODE]='O'))")
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40463017
before making this the control source of a control on your form, lets use the immediate window to do some testing.

Try the following in the immediate window (replace XXXXXX with a valid part number:
strCriteria = "[PART_NO] = 'XXXXXX'"
?strCriteria
?DSUM("[QTY_Ordered]", "tblInventory", strCriteria)

After typing or copying each of these lines, press the enter key.  Did everything work?
If not, then you have a problem with your [Part_NO] field.  If so, then try:

strCriteria = "[PART_NO] = 'XXXXXX' AND [TRNX_TYPE] = 'I'"
?strCriteria
?DSUM("[QTY_Ordered]", "tblInventory", strCriteria)

If that worked,then try
strCriteria = "[PART_NO] = 'XXXXXX' AND [TRNX_TYPE] = 'O'"
?strCriteria
?DSUM("[QTY_Ordered]", "tblInventory", strCriteria)

and finally:
strCriteria = "[PART_NO] = 'XXXXXX' AND [TRNX_TYPE] = IN ('I','O')"
?strCriteria
?DSUM("[QTY_Ordered]", "tblInventory", strCriteria)
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40463020
So, it wasn't [TRNX_TYPE] after all?

if, "this worked" then why did you give all the points to the other expert?
0
 

Author Comment

by:SteveL13
ID: 40463029
I typed wrong again.    It IS TYPE
0
 

Author Comment

by:SteveL13
ID: 40463031
This was the final:

=DSum("[QTY_ORDERED]","tblInventory","[PART_NO] = '" & [Forms]![frmParts]![txtPART_NO] & "' AND [TRNX_TYPE] in ('I','O')")
0

Featured Post

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

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

13 Experts available now in Live!

Get 1:1 Help Now