Solved

DSum Criteria

Posted on 2014-11-24
9
163 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
[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
  • 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:
Huseyin KAHRAMAN 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
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!

 

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

Expert Comment

by:Huseyin KAHRAMAN
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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

726 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