473,505 Members | 14,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to sum the records of a field?

Ali Rizwan
925 Contributor
Hi all,
I have a field in an access database name Cost i want to find the sum of all amount.
Database name = EXP
Using ADODC
VB6

I have a number of three adodcs on same form.
Plz give me the solution, using my information.

Tablename = EXP
DataBase name = Expenses
ADODC name = ADATA
Field name = Cost

Thanx
Oct 13 '07 #1
9 20409
nev
251 Contributor
Dim cval as Integer = 0

For i as integer = 0 to EXP.Count - 1
cval += val(EXP.Item("Cost", i).Value)
Next

MsgBox(cval.ToString)
Oct 15 '07 #2
debasisdas
8,127 Recognized Expert Expert
Try to use SQL for the purpose.
Oct 15 '07 #3
Ali Rizwan
925 Contributor
Dim cval as Integer = 0

For i as integer = 0 to EXP.Count - 1
cval += val(EXP.Item("Cost", i).Value)
Next

MsgBox(cval.ToString)
Hi,
Thanx for the answer but in which language you write it i want a code for vb6.
This code is not executing, and occuring somee errors on it.
Thanx
Oct 15 '07 #4
Ali Rizwan
925 Contributor
Try to use SQL for the purpose.
Sorry debasis,
but i don't know how to apply that code.
I tried but i said later i m recieving some errors.
Plz made an example code or that code
Thanx
Oct 15 '07 #5
dreamcode
2 New Member
Hi all,
I have a field in an access database name Cost i want to find the sum of all amount.
Database name = EXP
Using ADODC
VB6

I have a number of three adodcs on same form.
Plz give me the solution, using my information.

Tablename = EXP
DataBase name = Expenses
ADODC name = ADATA
Field name = Cost

Thanx
Hi,
Try the SQL query like,

rs.open "select sum(cost) from exp"

i hope this would help you.
All the best
Oct 15 '07 #6
Ali Rizwan
925 Contributor
Hi,
Try the SQL query like,

rs.open "select sum(cost) from exp"

i hope this would help you.
All the best
I m sorry.
What is cost means in the query can you plz explain it to me or made an example in vb6.
My app is delaying to the customer because of this only.
Thanx i ll very thak full to every body.
thanx again
Oct 15 '07 #7
muddasirmunir
284 Contributor
asalam o alikum
did you try this query in
"select sum(fieldname) as total from talblename "

replase filedname and tablename according to your tables
where fieldname=the field you want to count
talblename=the name of table weher you have a field
try this query




I m sorry.
What is cost means in the query can you plz explain it to me or made an example in vb6.
My app is delaying to the customer because of this only.
Thanx i ll very thak full to every body.
thanx again
Oct 15 '07 #8
Ali Rizwan
925 Contributor
asalam o alikum
did you try this query in
"select sum(fieldname) as total from talblename "

replase filedname and tablename according to your tables
where fieldname=the field you want to count
talblename=the name of table weher you have a field
try this query
Walaikumusallam

I m doing this query like this

Expand|Select|Wrap|Line Numbers
  1. Dim ras As Integer
  2.  
  3. ras = "select sum(Cost) as total from Exp "
  4. MsgBox ras
and the msgbox shows "select sum(Cost) as total from Exp " in message

Thanx
Oct 17 '07 #9
DeBees Consults
1 New Member
' I assume that your data base is connected and working fine


Dim SumCost As Double ' Declare as a global variable

Create a button name btnSUM and Caption it &Sum

Privte Sub btnSUM_Click()

SumCost = "0.00"

Do until ADATA.Recordset.EOF = True
If ADATA.RecordSet.Fields("Cost") <> "" then
SumCost = SumCost + ADATA.RecordSet.Fields("Cost")
End if
ADATA.Recordset.MoveNext
Loop
MsgBox("The sum of fields Cost = " SumCost)
' You can do whatever you want to do with SumCost here

' Possible Error: Where fields Cost is empty

' I hope this Suffices your purpose
' you can contact me on studybies@gmail.com
End Sub
Apr 18 '16 #10

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

Similar topics

1
10791
by: Patrizio | last post by:
Hi All, I've the following table with a PK defined on an IDENTITY column (INSERT_SEQ): CREATE TABLE MYDATA ( MID NUMERIC(19,0) NOT NULL, MYVALUE FLOAT NOT NULL, TIMEKEY ...
7
3273
by: Amy | last post by:
I'm trying to add an autoincrementing id to a table based on an existing field Name, but Name has duplicated records. How can I do that in ACCESS? Thanks. Amy
2
2293
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a...
1
498
by: Bridget Willey | last post by:
I am using ACT 6 and am trying to "split" the database between records for customers and junk records. The accounts designated as "customers" have that word in the ID field, and I am using that...
6
2496
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
3
1802
by: Chanchito | last post by:
hi there, I am seeking some guidance in regards to creating a query. I would like to be able to have the query display records that have had a certain amount of time pass since the time that is...
6
2112
by: Damon Grieves | last post by:
Hi I just want to be sure I understand how the Access client works. If I have an Access back end with a million records on a server and an Access client. If the client is installed on the users pc...
16
3460
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
1
3315
by: DonWolfi | last post by:
I am trying to get of our the database of our finance system all records where the the first field is the same and that either comply with condition a or condition b. Example: /<font...
3
2140
by: chalrav | last post by:
Reading through multiple records, with Loop capability -------------------------------------------------------------------------------- Hi, I have three tables as below: Table: Demand...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
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
7471
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...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.