Solved

DSum Criteria

Posted on 2014-11-24
9
160 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

765 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