Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy question - Error Trapping

Status
Not open for further replies.

kcmark

Technical User
Nov 2, 2002
63
US
OK - I know this is a silly question, but I cannot figure it out. I am trying to build in some error trapping on a data entry form. This form requires the user to enter various information, including several numbers (integers). The default value is 0 for the number fields. However, if the user deletes an entry in a number field (creating a nil value --> not zero but nil) then I want the form to automatically replace the nil with a 0. Here is the code I came up with:

Private Sub Com1_LostFocus()
If Com1 = "" Then
Forms!Rev_Add!Com1 = 0
End If
End Sub

The problem is that the statement is not recognizing the "" value when it occurs. I think it has something to do with Com1 being defined as an integer, but I am not sure. Any ideas?

 
Something like this ?
Private Sub Com1_LostFocus()
If IsNull(Com1) Then
Com1 = 0
End If
End Sub
You may also consider this:
If Val(Nz(Com1, 0)) = 0 Then Com1 = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top