473,657 Members | 2,492 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 20441
nev
251 Contributor
Dim cval as Integer = 0

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

MsgBox(cval.ToS tring)
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("C ost", i).Value)
Next

MsgBox(cval.ToS tring)
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
10798
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 INTEGER NOT NULL, TIMEKEY_DTTM DATETIME NULL,
7
3278
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
2301
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 simple "numbering records on a report" question. It is more complex than that. I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. ...
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 field as a lookup to separate these records from the rest of the database, which have nothing in the ID field. When I try to use the Export Wizard, it does not allow me the option to choose the lookup records to export. It seems to work, but when...
6
2499
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 products). Tables: tblCategoryDetails CategoryID SpecID
3
1810
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 listed a particular field of the record. There is a field labeld DispTime. This field is updated with the current time whenever data is typed into another field on the current record. What I am trying to figure out is how to create a query that...
6
2122
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 and run by the user...does Access drag the whole million records across the LAN when we call up one record ie filters for that record locally? If the client is on the same server as the back end, and the user starts up the client on the server...
16
3485
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 in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
1
3323
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 face='Courier' >field 1 field 2 field 3 field 4< >179000 990001 0 100.00< >179500 100001 TAB123 123.00< >180000 100002 TAB250 250.00<
3
2144
by: chalrav | last post by:
Reading through multiple records, with Loop capability -------------------------------------------------------------------------------- Hi, I have three tables as below: Table: Demand ITEM_ID, QUANTITY Item A, 10
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2735
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 we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.