VB Code:
Public Function getRecordCount(ByVal strTable As String) As Long
Dim tConn As ADODB.Connection
Dim rsaGetCount As ADODB.Recordset
Dim strSQL As String
' Default the return value.
getRecordCount = 0
Set tConn = New ADODB.Connection
tConn.Open [Connection string to your database]
strSQL = "SELECT COUNT(*) AS Cnt FROM " & strTable
Set rsaGetCount = New ADODB.Recordset
rsaGetCount.Open strSQL, tConn
getRecordCount = rsaGetCount("Cnt")
' Clean up.
On Error Resume Next
rsaGetCount.Close
Set rsaGetCount = Nothing
tConn.Close
Set tConn = Nothing
End Function