0 value returned if no record found

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two combo boxes that filter my records and return a single numerical
value.

What I want is the filter to return 0 if it finds no record. Is this possible?

Thanks again for the help.

Dave
 
from Rainbow01 Hong Kong

u can use NZ(Null to Zero) function
u can find it in Access Help

"Dave" 來函:
 
Hi,


Public Function ZeroIfNone( rst As DAO.Recordset)
If 0=rst.RecordCount then
ZeroIfNone=0
else
ZeroIfNone= rst.Fields(0).Value
End If
End Function




Since if you have no record, you have no ... value, you can't use Nz, since
Nz operates on a value which is NULL, you cannot apply it to ... absence.



Hoping it may help,
Vanderghast, Access MVP
 
First, if you build a filter form a form that returns no records, then
Me.Recordset.Recordcount will return 0

Second the function below makes absolutely no sense.
 
Hi,


The function returns 0 if there is no record in the recordset passed as
argument, else, if there are some records, it returns the value from the
first field of the actual record (or the first one, if just opened) of the
recordset.

It comes handy if your query, or filter, or whatever, is intended to
return just one single value but, on occasion, returns no record at all. The
proposed function then returns always something, the "expected" result, or
zero, if no record is found, as requested, at least, as I read it, by the
original poster.


Hoping it may help,
Vanderghast, Access MVP
 
I understood the code. I just don't see the point. It is a poor
substitution for:

Nz(DLookup("[SomeField", "SomeTable", "[Some Field] = " & Me.Combo1 _
& " AND [AnotherField] = " & Me.Combo2),0)
 
Back
Top