Checking to see if table holds records (1 Viewer)

mcdhappy80

Registered User.
Local time
Today, 15:29
Joined
Jun 22, 2009
Messages
347
What piece of code I need to put in form, to perform a check when form opens, to see if table that form depends on has no records?

Thank You
 

Scooterbug

Registered User.
Local time
Today, 09:29
Joined
Mar 27, 2009
Messages
853
off the top of my head, do a dcount:

Code:
Dim TotalRecords as Integer
 
TotalRecords = nz(dcount("*","TableName"),0)
 
if TotalRecords = 0 then
   'What to do if no records
end if
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 23:29
Joined
Jan 20, 2009
Messages
12,851
You can directly count the records in the form's record source using:
Me.Form.RecordsetClone.RecordCount
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 14:29
Joined
Sep 12, 2006
Messages
15,638
any idea which is quicker

dcount on the record source, or using the recordsetclone?

or is there no difference?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 23:29
Joined
Jan 20, 2009
Messages
12,851
any idea which is quicker

Don't know. Once the form is loaded the table would be in memory so I expect it is fairly quick either way. I assume producing the clone takes some time.

However counting the form's record source seems a more general and consistent solution to detecting and dealing with an empty form which is usually the ultimate purpose of this kind of task. Exactly the same line on any form rather than having to refer to a particular table or query.

I wonder what the comparison would be if the record source was a parameter query. Would the parameters be requested again for the DCount or would it just count the current incidence of the query?
 

Users who are viewing this thread

Top Bottom