Important:

Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog podem ser tratados como consultoria freelance.

Views

VBA Access - Retornando o número de Registros - Generic function to return number of records



Esta função retorna o número de registros de uma string SQL.

Dim lngRecs as Long
Dim strSQL as String

strSQL = "SELECT * from tblNames"

lngRecs = funRecordCount(strSQL)

Public Function funRecordCount (strSQL As String) As Integer
Dim dbs As Database
Dim rst As Recordset

On Error GoTo Error_funRecordCount
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot, dbSeeChanges)

' Find the number of records. First test records were found.
If (rst.EOF = True) And (rst.BOF = True) Then
funRecordCount = 0 ' No records found
Else
rst.MoveLast ' End of the recordset
funRecordCount = rst.RecordCount ' Number of records
End If

Exit_funRecordCount:
On Error GoTo 0
Set dbs = Nothing
Set rst = Nothing
Exit Function

Error_funRecordCount:
MsgBox "An unexpected situation arose in your program." & funCrLf & _
"Please write down the following details:" & funCrLf & funCrLf & _
"Module Name: modGeneric" & funCrLf & _
"Type: Module" & funCrLf & _
"Calling Procedure: funRecordCount" & funCrLf & _
"Error Number: " & Err.Number & funCrLf & _
"Error Descritption: " & Err.Description

Resume Exit_funRecordCount
End Function

Reference::


Tags: SQL, Access, record, occurs

Inline image 1

LinkWithinBrazilVBAAccessSpecialist

Related Posts Plugin for WordPress, Blogger...

Vitrine