Solved

DSum syntax with two form criteria

Posted on 2014-02-17
6
414 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 34

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 34

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now