Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DSum syntax with two form criteria

Posted on 2014-02-17
6
Medium Priority
?
423 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 40

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 40

Accepted Solution

by:
PatHartman earned 2000 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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 40

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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…
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.

824 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