Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql to count how many rows in a table

Status
Not open for further replies.

jamesmills

Technical User
Jul 30, 2003
43
GB
Hey people i need to find out what the sql code is for counting how many rows there are in a table.

Thanks
 
Yer i got it in the end! How thick am i!

Dim rs As Recordset
Dim finalDate As String

Set rs = CurrentDb.OpenRecordset("SELECT COUNT(*) FROM tblCustomers")
finalCount = rs
rs.Close

lblTotalCustomers.Caption = finalCount

Any idea why this will not work?
 
You're trying to assign rs, which is a recordset
object
, to "finalcount", which apparently isn't
even declared. (You have a "finaldate".) I
recommend you put "Option Explicit" in the declarations
section of your module to force declaration of all
variables.

You didn't mention you were trying to do this in code.
Since you've got a recordset object, you can get the
count from its RecordCount property, no need for SQL.

Code:
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblCustomers")
    cmdUpdate.Caption = rs.RecordCount
    
    rs.Close
    db.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top