By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,475 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,475 IT Pros & Developers. It's quick & easy.

How to test if records in Table?

P: n/a
I'm wondering if there is a better way to see if there are existing
records...

strRecCount = DCount("Cat_ID", "tblEntity", "[Cat_ID]=" &
[Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatAdm].Form![Cat_ID])

If this evaluates to 0 then there are no records in this category.

Is there a better way? If so, Why is it better?
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
TC
Simpler:

if dlookup (1, "MyTable") = 1 then
' table has at least one record.
endif

Dlookup only scans a single record (whereas Dcount potentially scans a
number of records). If there are no records, the dlookup returns NULL, which
fails all tests. If there are one or more records, it returns 1, & the test
succeeds. (In fact the two 1's could be anything - eg. 0's.) My code is also
independent of the field names & primary key of the table in question.

HTH,
TC
deko <dj****@hotmail.com> wrote in message
news:16***************@newssvr27.news.prodigy.com. ..
I'm wondering if there is a better way to see if there are existing
records...

strRecCount = DCount("Cat_ID", "tblEntity", "[Cat_ID]=" &
[Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatAdm].Form![Cat_ID])
If this evaluates to 0 then there are no records in this category.

Is there a better way? If so, Why is it better?

Nov 12 '05 #2

P: n/a
TC
Oops, I thought you said any records in the table. I now see you mean any
records in a specified category in the table. But the dlookup approach would
still work fine (with the addition of a 3rd parameter to define the
category).

HTH,
TC
TC <a@b.c.d> wrote in message news:1066300965.774038@teuthos...
Simpler:

if dlookup (1, "MyTable") = 1 then
' table has at least one record.
endif

Dlookup only scans a single record (whereas Dcount potentially scans a
number of records). If there are no records, the dlookup returns NULL, which fails all tests. If there are one or more records, it returns 1, & the test succeeds. (In fact the two 1's could be anything - eg. 0's.) My code is also independent of the field names & primary key of the table in question.

HTH,
TC
deko <dj****@hotmail.com> wrote in message
news:16***************@newssvr27.news.prodigy.com. ..
I'm wondering if there is a better way to see if there are existing
records...

strRecCount = DCount("Cat_ID", "tblEntity", "[Cat_ID]=" &

[Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatAdm].Form![Cat_ID])

If this evaluates to 0 then there are no records in this category.

Is there a better way? If so, Why is it better?


Nov 12 '05 #3

P: n/a
Yes, I considered using DLookup.

But I figured that Dcount would be quicker since it would be easier to
"count" than "lookup"

guess I was wrong... thanks for the tip!
"TC" <a@b.c.d> wrote in message news:1066301668.413688@teuthos...
Oops, I thought you said any records in the table. I now see you mean any
records in a specified category in the table. But the dlookup approach would still work fine (with the addition of a 3rd parameter to define the
category).

HTH,
TC
TC <a@b.c.d> wrote in message news:1066300965.774038@teuthos...
Simpler:

if dlookup (1, "MyTable") = 1 then
' table has at least one record.
endif

Dlookup only scans a single record (whereas Dcount potentially scans a
number of records). If there are no records, the dlookup returns NULL,

which
fails all tests. If there are one or more records, it returns 1, & the

test
succeeds. (In fact the two 1's could be anything - eg. 0's.) My code is

also
independent of the field names & primary key of the table in question.

HTH,
TC
deko <dj****@hotmail.com> wrote in message
news:16***************@newssvr27.news.prodigy.com. ..
I'm wondering if there is a better way to see if there are existing
records...

strRecCount = DCount("Cat_ID", "tblEntity", "[Cat_ID]=" &

[Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatAdm].Form![Cat_ID])

If this evaluates to 0 then there are no records in this category.

Is there a better way? If so, Why is it better?



Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.