Show 0 when adding total from query that has no results

B

BZeyger

I have a subform that runs a query. The detail section of the subform contains:
txtProject (Project Name)
txtHours (Project Hours works)

The subform footer contains a textbox for the sum.
txtHoursTot

The control source for txtHoursTot is:
=Sum([Hours])

This works fine. However, if the query does not retrieve any information,
txtHoursTot is blank. What would I have to do to show 0 if there aren’t any
results (The query would never retrieve 0 hours based on user entry).

I use 3 subforms that have this same format. At the end, I add the Total
Hours from each subform. If one of them is blank, I get an #Error. I would
like to get around this error.
 
F

fredg

I have a subform that runs a query. The detail section of the subform contains:
txtProject (Project Name)
txtHours (Project Hours works)

The subform footer contains a textbox for the sum.
txtHoursTot

The control source for txtHoursTot is:
=Sum([Hours])

This works fine. However, if the query does not retrieve any information,
txtHoursTot is blank. What would I have to do to show 0 if there aren¢t any
results (The query would never retrieve 0 hours based on user entry).

I use 3 subforms that have this same format. At the end, I add the Total
Hours from each subform. If one of them is blank, I get an #Error. I would
like to get around this error.

Look up the NZ function in VBA help.
=Sum(Nz([Hours],0))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top