Solved

DSum syntax with two form criteria

Posted on 2014-02-17
6
417 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
  • 3
  • 3
6 Comments
 
LVL 36

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 36

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 36

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
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 …

756 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