When Count = 0.

  • Thread starter Thread starter Sirocco
  • Start date Start date
S

Sirocco

I have a control defined by Count(*) and I call it "Count". In some code
I say "If Count >0, do this". but when the count is 0, it bombs. How do I
handle the case where Count is 0?

Many thanks in advance.
 
It bombs? Which means what -- it errors? it stops? nothing happens the way
you want? nothing happens at all? Post your code.
 
I'm counting the number of records in a subform. I get an error message "
....expression has no value". But that makes sense because if there are no
records in the subform, the textbox defined by Count(*) is blank, rather
than 0, but I'm having trouble implementing this in the following code. I
was trying to avoid details, but generally, it's

If [subform]![RecordCounterField] >0 then
[subform].visible = True
Else
[subform].visible = False

I have the same kind of strategy in another part of the database, which
works, but the case where counter = 0 isn't an issue there for reasons I
won't go into (if it were I could simply use the same logic).

I look forward to your or anyone's response.
Thanks.
 
Perhaps this will do the trick for you:

[subform].visible = ([subform].Form.RecordsetClone.RecordCount <> 0)


--

Ken Snell
<MS ACCESS MVP>

Sirocco said:
I'm counting the number of records in a subform. I get an error message "
...expression has no value". But that makes sense because if there are no
records in the subform, the textbox defined by Count(*) is blank, rather
than 0, but I'm having trouble implementing this in the following code. I
was trying to avoid details, but generally, it's

If [subform]![RecordCounterField] >0 then
[subform].visible = True
Else
[subform].visible = False

I have the same kind of strategy in another part of the database, which
works, but the case where counter = 0 isn't an issue there for reasons I
won't go into (if it were I could simply use the same logic).

I look forward to your or anyone's response.
Thanks.




Ken Snell said:
It bombs? Which means what -- it errors? it stops? nothing happens the way
you want? nothing happens at all? Post your code.

--

Ken Snell
<MS ACCESS MVP>

some
code do
 
Ah, the RecordsetClone, there it is again! And it works. A single line of
code. I noticed this morning that for reports one can use the HasData
Property or the NoData event to achieve a similar effect. I wonder why
such a useful effect in a form is so unintuitive or hard to come by.
Thank you very much.

Brian
 
Back
Top