How to test if records in Table?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • deko

    How to test if records in Table?

    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_CatA dm].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?


  • TC

    #2
    Re: How to test if records in Table?

    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 <dje422@hotmail .com> wrote in message
    news:16ujb.1380 $1_.345@newssvr 27.news.prodigy .com...[color=blue]
    > I'm wondering if there is a better way to see if there are existing
    > records...
    >
    > strRecCount = DCount("Cat_ID" , "tblEntity" , "[Cat_ID]=" &
    >[/color]
    [Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatA dm].Form![Cat_ID])[color=blue]
    >
    > If this evaluates to 0 then there are no records in this category.
    >
    > Is there a better way? If so, Why is it better?
    >
    >[/color]


    Comment

    • TC

      #3
      Re: How to test if records in Table?

      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 ...[color=blue]
      > 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,[/color]
      which[color=blue]
      > fails all tests. If there are one or more records, it returns 1, & the[/color]
      test[color=blue]
      > succeeds. (In fact the two 1's could be anything - eg. 0's.) My code is[/color]
      also[color=blue]
      > independent of the field names & primary key of the table in question.
      >
      > HTH,
      > TC
      >
      >
      > deko <dje422@hotmail .com> wrote in message
      > news:16ujb.1380 $1_.345@newssvr 27.news.prodigy .com...[color=green]
      > > I'm wondering if there is a better way to see if there are existing
      > > records...
      > >
      > > strRecCount = DCount("Cat_ID" , "tblEntity" , "[Cat_ID]=" &
      > >[/color]
      >[/color]
      [Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatA dm].Form![Cat_ID])[color=blue][color=green]
      > >
      > > If this evaluates to 0 then there are no records in this category.
      > >
      > > Is there a better way? If so, Why is it better?
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • deko

        #4
        Re: How to test if records in Table?

        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 ...[color=blue]
        > 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[/color]
        would[color=blue]
        > 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 ...[color=green]
        > > 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,[/color]
        > which[color=green]
        > > fails all tests. If there are one or more records, it returns 1, & the[/color]
        > test[color=green]
        > > succeeds. (In fact the two 1's could be anything - eg. 0's.) My code is[/color]
        > also[color=green]
        > > independent of the field names & primary key of the table in question.
        > >
        > > HTH,
        > > TC
        > >
        > >
        > > deko <dje422@hotmail .com> wrote in message
        > > news:16ujb.1380 $1_.345@newssvr 27.news.prodigy .com...[color=darkred]
        > > > I'm wondering if there is a better way to see if there are existing
        > > > records...
        > > >
        > > > strRecCount = DCount("Cat_ID" , "tblEntity" , "[Cat_ID]=" &
        > > >[/color]
        > >[/color]
        >[/color]
        [Forms]![frmTools]![frmToolsControl].Form![frmCatEdit_CatA dm].Form![Cat_ID])[color=blue][color=green][color=darkred]
        > > >
        > > > If this evaluates to 0 then there are no records in this category.
        > > >
        > > > Is there a better way? If so, Why is it better?
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...