I bumped into a need to query the FE DB to find out if an Access table is empty.
I came up with the following query which appears to work as desired:
When not empty this at least puts only one record in the adoRS object. Suggestions I found do to "SELECT * / SELECT 1" filled the record set with as many records as is in the table, so I deem those suggestions as less efficient.
Any suggestions as to a better way to optimize this IsEmpty check?
I came up with the following query which appears to work as desired:
Code:
Dim adoRS As ADODB.Recordset
Dim strSQL As String
'Define a query to test if the table is empty
strSQL = "SELECT DISTINCT 1 " & _
"FROM " & strTableName & ";"
'Define attachment to database table specifics and execute commands via With block
Set adoRS = New ADODB.Recordset
With adoRS
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strSQL
'Was no record found?
If .BOF Or .EOF Then
dbutils_ISFETableEmpty = True
Else
dbutils_ISFETableEmpty = False
End If
'Close the database table
.Close
End With
'Clean up the connection to the database
Set adoRS = Nothing
Any suggestions as to a better way to optimize this IsEmpty check?