Thread: Count Record
View Single Post
  #2 (permalink)  
Old November 27th, 2006, 07:28 AM
leehambly leehambly is offline
Friend of Wrox
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly


Very simply, to count the records in a table and return the value in a msgbox...

================================================== ===============
Public Function pfunCountRecords(strTableName as string) as Long
dim rst as recordset
dim strMsg as string
dim strTitle as string
dim lngCount as long

strTitle = "Record Count"
set rst = currentdb.openrecordset(strTableName)
lngCount = rst.recordcount

set rst = nothing

strMsg = "There are " & lngCount & " record(s) in " & strTableName
msgbox strMsg, vbInformation, strTitle

pfunCountRecords = lngCount

End Function
================================================== ===============

So, as a function this returns the record count value as part of the function, but also pops up a msgbox with the same information.

If it is more than a table you want to evaluate, change the input to a SQL statement instead and evaluate that.

Reply With Quote