Brett Barabash
BBarabash at TappeConstruction.com
Wed May 25 12:52:51 CDT 2005
What about DLookup("MyField", "MyTable")?
Or is that too simple? ;-)
/could also use DCount, but I would imagine that performance would
suffer on big tables.
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan,
Lambert
Sent: Wednesday, May 25, 2005 12:41 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Record count
Try this...
Function bIsTableEmpty(strDataSource As String) As Boolean Dim db As
DAO.Database Dim rs As DAO.Recordset
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset(strDataSource, dbOpenForwardOnly)
With rs
On Error Resume Next
.MoveFirst
If Err.Number <> 0 Then bIsTableEmpty = True
On Error GoTo 0
bIsTableEmpty = .EOF
.Close
End With
Set rs = Nothing
Set db = Nothing
End Function
If the table / query has no records then the .MoveFirst line will cause
an error. This is trapped to give you the result you want.
HTH
Lambert
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Hale, Jim
Sent: Wednesday, May 25, 2005 1:19 PM
To: 'Accessd (E-mail)
Subject: [AccessD] Record count
What is the easiest way in code to determine if a table has at least one
record? TIA
Jim Hale
--------------------------------------------------------------------------------------------------------------------
The information in this email may contain confidential information that
is legally privileged. The information is only for the use of the intended
recipient(s) named above. If you are not the intended recipient(s), you
are hereby notified that any disclosure, copying, distribution, or the taking
of any action in regard to the content of this email is strictly prohibited. If
transmission is incorrect, unclear, or incomplete, please notify the sender
immediately. The authorized recipi
s) of this information is/are prohibited
from disclosing this information to any other party and is/are required to
destroy the information after its stated need has been fulfilled.
Any views expressed in this message are those of the individual
sender, except where the sender specifies and with authority,
states them to be the views of Tappe Construction Co.
This footer also confirms that this email message has been scanned
for the presence of computer viruses.Scanning of this message and
addition of this footer is performed by SurfControl E-mail Filter software
in conjunction with virus detection software.