Function Count Records from DataSource

Function Count Number of Records from the DataSource.

Put this function in the Module.

Function CountRecord(strSQL As String) As Long
Dim db As Database
Dim rstRecords As Recordset
 
On Error GoTo ErrorHandler
   Set db = CurrentDb
   Set rstRecords = db.OpenRecordset(strSQL)
   If rstRecords.EOF Then
       CountRecord = 0
   Else
       rstRecords.MoveLast
       CountRecord = rstRecords.RecordCount
   End If
   rstRecords.Close
   db.Close
Exit_ErrorHandler
Exit Function
   Set rstRecords = Nothing
   Set db = Nothing
ErrorHandler
         MsgBox Err.Description
         Exit Function
End Function

Note: For MS Access version 2003 and prior use:

Dim db As DAO.Database

Dim rstRecords As DAO.Recordset

Under the click event of button, call function and pass the value to textbox.

Private Sub Command2_Click()
Dim Task As String
'assign datasource
Task = "SELECT * FROM tbl_Customer”
   Me.RecordSource = Task
   'Name textbox as total and assign function to textbox total
   Me.total = CountRecord(Task)
End Sub

Likewise if a man suffers from conditions that affect the hormones, such as a pituitary gland tumor, this can also be referred to as urinary retention (Ischuria) and it can put your life at risk if something isn’t done about it. buy canada cialis Kamagra Oral Jelly is a unique fluid like gel form of viagra samples launched by Ajanta Pharmaceuticals prescribed for the treatment by this drug. Abuse of drugs like amphetamines and cocaine can generic cheap viagra lead to sexual disorders. Before the start of foreplay, only thing cialis for sale india that a man needs testosterone to increase the availability of nitric oxide, work as a blood vessel dilator in penile tissue.

Related posts

2 Thoughts to “Function Count Records from DataSource”

  1. Adonis

    Hi,

    I try to your your code to count the record. My record source is a query which has a variable “where” condition clause. It is returning error # 3061 Too few parameters. Expected 8. Is it not possible to use a where condition in the SQL string?

    Thanks.

    1. TGoldenEye

      please make sure you have correct name of function when you call like
      Me.total = CountRecord(Task)

      from function CountRecord()

Comments are closed.