Solved

DSum Criteria

Posted on 2014-11-24
9
166 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 48

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 55

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

 

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 55

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 48

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 48

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

707 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