Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleCount the records in a database table
Keywordsdatabase, table, count records
CategoriesDatabase
 
Use a SQL statement like this one:

    SELECT COUNT (*) FROM table
 
' Return the number of records in the table.
Private Sub cmdCount_Click()
Dim db As Database
Dim rs As Recordset

    On Error GoTo DataError
    
    ' Open the database.
    Set db = OpenDatabase(txtDatabase.Text)

    ' Open the recordset.
    Set rs = db.openrecordset( _
        "SELECT COUNT (*) FROM " & txtTable.Text)
        
    ' Display the result.
    lblCount.Caption = "Table has " & _
        Format$(rs.fields(0)) & " records."

    rs.Close
    db.Close
    
    Exit Sub

DataError:
    MsgBox "Error " & Err.Number & _
        " counting records." & _
        vbCrLf & vbCrLf & Err.Description
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated