Determing Empty Tables or Queries in MS Access

Determing Empty Tables or Queries in MS Access

You can determine whether an Access table or query, accessed via RECORDSET OBJECT, contains any record by examining the boolean type BOFand EOF propertyof that RECORDSET OBJECT. If the RECORDSET contains no recordor is empty, then the value of both properties is TRUE, that is, BOF = TRUE andEOF = TRUE.

Call the following function to minimize your program code:

 Function Recordset_Empty(Rs as Recordset)    Recordset_Empty = False    If Rs.BOF And Rs.EOF Then  
Recordset_Empty = TrueEnd Function

If RECORDSET OBJECT is empty, then this function returns TRUE. Otherwise,it returns FALSE. Example:

 Dim DatabaseName as stringDim rs Personnel as RecordsetDim dbPayroll as Database'Set the MS ACCESS database file nameDatabaseName = "C:DATAPAYROLL.MDB"Set dbPayroll = DbEngine.Workspaces(0)
.OpenDatabasse(DatabaseName)Set rsPersonnel = dbPayroll.OpenRecordset
("PERSONNEL")If Recordset_Empty(rsPersonnel) then 'Table PERSONNEL contains no record Msgbox "PERSONNEL table is empty."EndIf


Share the Post: