Knowing if a column is empty

  • Thread starter Thread starter Maracay
  • Start date Start date
M

Maracay

Hi guys

There is a better way to know if a column in a table is empty?, what I am
doing is to read all the table but takes too long when I have 10.000 records
or more in the table, this is my code:

Dim rd As Recordset
Set rd = Recordset
rd.MoveFirst
swID = False
swPrefix = False
Do Until rd.EOF
If Not IsNull(ID) Then
swID = True
End If
If Not IsNull(Prefix) Then
swPrefix = True
End If
rd.MoveNext
Loop
 
you want to know if even just one record in the table has a value in a
specific field? try using a DCount() function, as

swID = (DCount(1,"TableName","ID Is Not Null") > 0)

replace TableName with the correct name of the table.

hth
 
I think you've got a typo there, Tina:

swID = (DCount("*","TableName","ID Is Not Null") > 0)
 
not a typo; i usually use 1 rather than an asterisk; i've had problems with
"*" erring in A97, which is the version i've been using almost exclusively
the last few years.
 
Interesting. I, too, use Access 97 almost exclusively, and I've never had a
problem using "*"
 
Back
Top