Solved

DSum syntax with two form criteria

Posted on 2014-02-17
6
419 Views
Last Modified: 2014-02-17
I have a syntax issue with the folloing code using two criteria.  Can someone spot the problem?

Me.txtAvailQty = DSum("[IncomingQty]", "tblInventoryDetails", -"[SoldQty]", "tblInventoryDetails", "[ProductID] = " & [Forms]![frmInventory]![txtProdID], "[LocationID] " & [Forms]![frmInventory]![txtToID])
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
  • 3
  • 3
6 Comments
 
LVL 38

Expert Comment

by:PatHartman
ID: 39864844
Me.txtAvailQty = DSum("[IncomingQty]", "tblInventoryDetails",  "tblInventoryDetails", "[ProductID] = " & [Forms]![frmInventory]![txtProdID] & " AND [LocationID] = " & [Forms]![frmInventory]![txtToID])

Sometimes it is easier to understand SQL Strings if you build them as a variable so you can see the results of your effort.

Dim strWhere As String
strWhere =   "[ProductID] = " & [Forms]![frmInventory]![txtProdID] & " AND [LocationID] = " & [Forms]![frmInventory]![txtToID])

Me.txtAvailQty = DSum("[IncomingQty]", "tblInventoryDetails", "tblInventoryDetails", strWhere)

PS -- I removed ---- -"[SoldQty] ", --- because I couldn't figure out what it went to.  It isn't the table/query name and didn't have any variable to compare to so it didn't look like it should be part of the where clause.
0
 

Author Comment

by:SteveL13
ID: 39864949
I have to have SoldQty because AvailQty - Sum of IncomingQty minus Sum of SoldQty
0
 
LVL 38

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39865126
You can only get a single column from a domain function.

Is SoldQty in the same table as IncomingQty?  

There are two possible solutions and I don't know which will give you the answer you need.  Probably the second one since I suspect that each transaction would be in a separate record.

Me.txtAvailQty = DSum("[IncomingQty] - [SoldQty]", "tblInventoryDetails", "tblInventoryDetails", strWhere)

OR

Me.txtAvailQty = DSum("[IncomingQty]", "tblInventoryDetails", "tblInventoryDetails", strWhere) - DSum("[SoldQty]", "tblInventoryDetails", "tblInventoryDetails", strWhere)
0
Independent Software Vendors: 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: 39865364
This worked...

Me.txtAvailQty = DSum("[IncomingQty]", "tblInventoryDetails", "tblInventoryDetails", strWhere) - DSum("[SoldQty]", "tblInventoryDetails", "tblInventoryDetails", strWhere)

but I had to remove the double "tblInventoryDetails" in 2 place.   Thanks.

--Steve
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39865685
I just washed my hands and can't do a thing with them.  Glad you worked it out.
0
 

Author Comment

by:SteveL13
ID: 39865873
But your solution worked.  I just spotted the double "tblInventoryDetails".  At least I know how to do that.  Thanks again.  I appreciate your efforts.
0

Featured Post

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

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.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

623 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