How to Return the number of records in the table.
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 'Database - How to Return the number of records in the table. Option Explicit 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 Private Sub Form_Load() txtDatabase.Text = App.Path & "\books.mdb" txtTable.Text = "Books" End Sub |