Don't Delete the Zeros! Help

G

Guest

I have multiple forms with several data input controls that default to zeros.
Calculations are made from these controls and if the zero is deleted the
results error out. In the past I have added to following afterupdate code to
each control to prevent the error.

Private Sub BrokerCredit_AfterUpdate()
If IsNull(BrokerCredit) Then
BrokerCredit = 0
End If
End Sub

Due to the number of these controls I am seeking a way to handle this
without adding an afterupdate event to each control. Is there an easier way?
Any help would be greatly appreciated!

Thanks
 
D

Douglas J. Steele

You could leave the Nulls as they are, and create a query that uses the Nz()
function to convert the Nulls to zeroes. You could then use the query
wherever you would otherwise have used the table.
 
T

tina

well, as a labor-saver, you could do the following:

open (or create) a standard module and paste the following function into it,
as

Public Function isDefaultZero()

If IsNull(Screen.ActiveControl) Then Screen.ActiveControl = 0

End Function

open your form in design view. select *all* the controls that you want to
default back to zero. in the Properties box, add the following expression
directly on the AfterUpdate property's line, as

=isDefaultZero()

because you selected all the controls, the expression will be added to the
event line of all the controls at the same time.

hth
 

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