Discussion Locked
0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How can I determine the number of records in a table programmatically using VBA?
1 reply
by bschaettle
This is crude, bu it works...
Function NumberOfRecords(sTableName as String) as integer
Dim MyRecordset As Recordset
Dim MyQueryDef As QueryDef
Dim MySQL As String
NumberOfRecords = 0
On Error GoTo ErrHandler
Set MyQueryDef = Nothing
Set MyRecordset = Nothing
MySQL = "SELECT * FROM " & sTableName
Set MyQueryDef = _
CurrentDb.CreateQueryDef("", MySQL)
Set MyRecordset = MyQueryDef.OpenRecordset(dbOpenDynaset, dbSeeChanges, dbOptimistic)
NumberOfRecords = MyRecordset.RecordCount
ErrHandler:
On Error GoTo 0
MyRecordset.Close
Set MyRecordset = Nothing
MyQueryDef.Close
Set MyQueryDef = Nothing
End Function
This discussion is closed to new replies.
Trending Software posts
Sort by Trending
Discussion
Useful software Tip or Shortcut
0 helpful
1 reply
1 helpful
1 reply
Question Unanswered
How Are Teams Testing AI-Generated Code Before Production?
0 helpful
0 replies
0 helpful
5 replies
0 helpful
20 replies