Getting total number of records

  • Thread starter Thread starter H. Martins
  • Start date Start date
H

H. Martins

Hi.

I Need to get the number of records from a table not referenced in the
form where the total is supposed to show but from another form.

I suppose I can get the value directly from the table or from the form
containing the table.

Can I have some help please?

H. Martins
 
Hi.

I Need to get the number of records from a table not referenced in the
form where the total is supposed to show but from another form.

I suppose I can get the value directly from the table or from the form
containing the table.

Can I have some help please?

H. Martins

Here is the basic code:

dim db as dao.database
dim rs as dao.recordset
dim TotalRecords as long
set db=currentdb()
set rs=db.openrecordset("tblTable2",dbopentable)
rs.movelast
TotalRecords=rs.RecordCount
rs.close
db.close

This could easily be turned into a function:

public function GetRecordCount(sTable as string) as long
dim db as dao.database
dim rs as dao.recordset
on error goto ErrorTrap
GetRecordCount=0
set db=currentdb()
set rs=db.openrecordset(sTable,dbopentable)
if not rs.eof then
rs.movelast
GetRecordCount=rs.RecordCount
endif
rs.close
db.close
exit function
ErrorTrap:
end function

Or you could use the dcount( ) function which is explained in Help.
 
Hi.

I Need to get the number of records from a table not referenced in the
form where the total is supposed to show but from another form.

I suppose I can get the value directly from the table or from the form
containing the table.

Can I have some help please?

H. Martins

=DCount("*","TableName")

will return the number of records in your table.
 
Back
Top