|
-
Jul 25th, 2008, 04:38 AM
#1
Thread Starter
Fanatic Member
Counting records in Data Control...
How do you count and add up all the records in one field of the Microsoft Access using data control?...
Situation:
I made a database using MSAccess. I made two forms. One for inputting the quantities for selling and the other one is for checking how many quantities have been sold out. So every time that you sell, the record gets save. And when I go to the second form, I will see how many things I've been sold..
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
-
Jul 25th, 2008, 06:02 AM
#2
Re: Counting records in Data Control...
Is there a reason you are using a dreaded Data Control?
For an explanation of why it is a bad idea (and a link to the recommended alternative), see the article Why is using bound controls a bad thing? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)
Anyhoo.. to do what you want, run an SQL statement like this:
"SELECT Sum(FieldName) as MyTotal FROM tablename"
This will return just one row containing one column (called MyTotal), which will have the total in it.
-
Jul 25th, 2008, 07:16 AM
#3
Re: Counting records in Data Control...
To count the total number of records in a database.. use the below code:
Code:
If data1.recordset.absoluteposition > -1 then
data1.recordset.movelast
Rec_Count=data1.recordset.recordcount 'stores the total number of records
data1.recordset.movefirst
data1.refresh
else
Rec_Count=0 ' shows empty database
msgbox "Empty"
end if
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 25th, 2008, 08:43 AM
#4
Thread Starter
Fanatic Member
Re: Counting records in Data Control...
 Originally Posted by si_the_geek
Is there a reason you are using a dreaded Data Control?
For an explanation of why it is a bad idea (and a link to the recommended alternative), see the article Why is using bound controls a bad thing? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)
Anyhoo.. to do what you want, run an SQL statement like this:
"SELECT Sum(FieldName) as MyTotal FROM tablename"
This will return just one row containing one column (called MyTotal), which will have the total in it.
Well, I've been using the Data Control because it is the basic control use in database. But, somehow I heard that the ADO Data Control has a lot of functions and codes. But, I have to master the basics first before moving on to the advance...
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
-
Jul 25th, 2008, 08:44 AM
#5
Thread Starter
Fanatic Member
Re: Counting records in Data Control...
@akhileshbc
I'll try your codes at home.. I'm currently at work... Thanks!
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
-
Jul 25th, 2008, 08:48 AM
#6
Re: Counting records in Data Control...
What SI is saying is Do Not Use the Data Controls. Lean ADO and SQL.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jul 25th, 2008, 08:57 AM
#7
Thread Starter
Fanatic Member
Re: Counting records in Data Control...
 Originally Posted by GaryMazzone
What SI is saying is Do Not Use the Data Controls. Lean ADO and SQL.
I'm only temporary using Data Control because I want to learn the basics of Database making. And besides, I don't want to get too much advance from our studies.
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|