Results 1 to 7 of 7

Thread: Counting records in Data Control...

  1. #1

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  4. #4

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    Re: Counting records in Data Control...

    Quote 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

  5. #5

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    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

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  7. #7

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    Re: Counting records in Data Control...

    Quote 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
  •  



Click Here to Expand Forum to Full Width