Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How replace empty number field with a "0.00"

Posted on 2013-06-14
8
Medium Priority
?
343 Views
Last Modified: 2013-06-14
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
Comment
Question by:SteveL13
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:Guru Ji
ID: 39247558
you can try this

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

Expert Comment

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

scott c
0
 
LVL 20

Expert Comment

by:clarkscott
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

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

Expert Comment

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

=Nz([1000],0)

/gustav
0
 
LVL 52

Expert Comment

by:Gustav Brock
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

by:SteveL13
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 52

Accepted Solution

by:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

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

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

Join & Ask a Question