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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get total records no. from data base

Status
Not open for further replies.

cmaknp

Programmer
Aug 28, 2002
25
IN
How to write command

how to get total record in any database.?

& also how to know..current record no. in database.?

pls help
 
pls anyone can help me, becoz i m getting eror again & again, so anyone can tell me..
that how to get total no. of record in textbox or label, & as well as current record.
 
What data access methods are you using - DAO, ADO, etc.? Look up RecordCount and AbsolutePosition property in the online help.

Hope this helps

Daren
 
Post code showing where error occurs - tell us what error you're getting.

READ FAQ referred below! Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Hi,
I don't consider this to be the most efficient method but you could try.

In the load event of the form that contains the text box put in the following code:

Private Sub Form_Load()
Dim db as DAO.Database
Dim rs as DAO.Recordset
Dim tdfs as DAO.TableDefs
Dim tdf as DAO.TableDef
Dim total as long
total = 0
Set db = CurrentDb
Set tdfs = db.TableDefs
For Each tdf In tdfs
Set rs = db.OpenRecordset(tdf.Name, dbOpenDynaset)
If rs.RecordCount > 0 Then
rs.MoveLast
rs.MoveFirst
total = total + rs.RecordCount
End If
rs.Close
Next tdf
Me.Text1 = total

End Sub

The problem with this code is that it will return the record count of tables in the database including the MSysObjects and so. So if you wnat to have only the records in the tables that you created counted, then you must hard code each table name into the system.
With regards,
PGK
 
With a dao recordset you can do it this way.
This was set up in the form load procedure. Dim lastRecord as integer in the Declarations Section


Dim dbsOurMembers As Database
Dim rstLocalMembers As Recordset
Set dbsOurMembers = OpenDatabase("c:\YourFolder\YourDatabase.mdb")
'
With rstLocalMembers
.MoveLast
LastRecord = .RecordCount
.MoveFirst
End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top