473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to use the DSum Method with multiple Criterias

I have a table with multiple records and I need to sum the Total Amount [CostoTotal] when the type of record [TipoMovimiento] is one field in my form and the Code of the product is another filed in my form.

This is an inventory table and my code is below

Private Sub Command0_Click()
Dim Test As Currency
Test = DSum("[CostoTotal]", "tblInventarioMovimientos", "[TipoMovimiento] <> [Text2] AND [Codigo] = " & [Text1])

End Sub
Mar 31 '10 #1
1 6989
patjones
931 Expert 512MB
The way that you wrote the criteria in the DSum function isn't going to work because [Text2] is included inside the string rather than being concatenated with it. Try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2. Dim Test As Currency
  3. Test = DSum("[CostoTotal]", "tblInventarioMovimientos", "[TipoMovimiento] <> " & [Text2] & " AND [Codigo] = " & [Text1])
  4. End Sub 

This will work if the comparisons involve numbers. But if [Text1] and [Text2] are string types then this has to be modified slightly as


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2. Dim Test As Currency
  3. Test = DSum("[CostoTotal]", "tblInventarioMovimientos", "[TipoMovimiento] <> '" & [Text2] & "' AND [Codigo] = '" & [Text1] & "'")
  4. End Sub 
Mar 31 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: herbert | last post by:
1) I created a class Person whose objects are stored in collections. Using IComparable allows to define one sort criteria like name. Best practice: How can I add more sort criterias like age, zip,...
1
by: smita | last post by:
Hi, I want to search an xml file for particular searchstrings and also based on the date i.e. all items containing the date -----prior to the specified date, or ----on that date or ----- after the...
1
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression. It relates to a subform (sfrmCost) from which I'm wanting to extract the grand total of any and all data rows...
0
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression, or maybe even DCount might be an alternative. I have tried numerous combinations, but with no apparent success....
2
by: Dalan | last post by:
I seemed to be having problems with structuring the use of NZ with a DSum expression. Having tried numerous variations of the expression without success, I'm asking for assistance. First some...
9
by: BlackJack17 | last post by:
Alright you all have been so helpful with everything else that I thought I'd run one more issue by you. I have put together a report that is driven by a query. This query (Unique Records) returns...
19
by: dozingquinn | last post by:
Hello, Thanks to a previous helper I found some great Dsum info here: http://www.mvps.org/access/general/gen0018.htm Unfortunately I can't get the code to work for my requirements. I'm...
13
by: 19bam80 | last post by:
I am using a simple DSum function to add donations made by each member of an organization. It looks like this: dTotal = DSum("SplitAmt", "", " = " & Format(lGiftID)) SplitAmt is the field that...
7
by: Lewe22 | last post by:
I have a query pulling information from multiple tables, one of which contains a list of students with an auto number their assessment information and how long the assessment took in minutes . ...
2
by: Gulnarambi | last post by:
I have a form in datasheet view with Total and Currency text boxes, in Currency text box I only can enter values of AZN and USD. Form is based on Table and as criterias information fromUnbound...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.