Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# How replace empty number field with a "0.00"

Posted on 2013-06-14
Medium Priority
342 Views
On a form field I have a number field.  It the user clears the value in the field I want to replace it with a 0.00.

I've tried this but it doesn't work: (the field name is "1000"

=IIf([1000]="",0,[1000])
0
Question by:SteveL13
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 3
• 2
• 2
• +1

LVL 11

Expert Comment

ID: 39247558
you can try this

IIf(Nz(1000.value) = vbNullString,0,[1000])
0

LVL 20

Expert Comment

ID: 39247561
If this is a numeric field...it will not = "".
iif(isnull([1000]),0,[1000])

scott c
0

LVL 20

Expert Comment

ID: 39247567
Plus... you can forma a 0 to look like 0.00  ... but 0.00 is not a legitimate number.
1.0 = 1
1.1 = 1.1

0.00 = 0

etc.

scott C
0

Author Comment

ID: 39247593
IIf(Nz(1000.value) = vbNullString,0,[1000])  did not work.
0

LVL 51

Expert Comment

ID: 39247620
This should do for the value in _another_ field than [1000]:

=Nz([1000],0)

/gustav
0

LVL 51

Expert Comment

ID: 39247634
If you only have this field, use this in the AfterUpdate event:

If IsNull(Me![1000].Value) Then
Me![1000].Value = 0
End If

/gustav
0

Author Comment

ID: 39247677
=Nz([1000],0)  did not work.

If IsNull(Me![1000].Value) Then
Me![1000].Value = 0
End If

did work but I have 45 fields to code.
0

LVL 51

Accepted Solution

Gustav Brock earned 2000 total points
ID: 39247793
Auch. You can use WithEvents to extend the form class module, but that's a learning experience.

Another option is to create a helper subfunction:

Public Sub UpdateNullToZero(ByRef ctl As Control)
If IsNull(ctl.Value) Then
ctl.Value = 0
End If
End Sub

Now, in the AfterUpdate events you just need to paste:

Call UpdateNullToZero(Me.ActiveControl)

/gustav
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 hâ€¦
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if youâ€™re going to set referential integrity: Decide if you want cascade updaâ€¦
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filledâ€¦
###### Suggested Courses
Course of the Month11 days, 13 hours left to enroll

#### 730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.