Setting DefaultValue to null - numeric field

S

Stu

How do I set the defaultValue property to null for a text box where the
control source is a number AND the control source's table field has a default
value of 0? I want the form field to display nothing, superceding the table
field default of 0. Currently the field displays 0, the default table value.
 
T

tina

a DefaultValue isn't a "display" value, it's hard data. if the field's
DefaultValue is set to zero at the table level, then you're going to get a
zero value in that field when a record is created, period. if you want to
*hide* that hard data in a form, then read up on the Format property in
Access Help. an easy way to get to the topic is to open the form in Design
view, click on the control to select it, click in the Format property line
in the Properties box, and press F1.

hth
 
G

Golfinray

There is a property under the data tab in properties that say default value.
Set it to
=is null
 
L

Linq Adams via AccessMonster.com

Of course, the question begging to be asked is, why not simply have the
Default Value in the Table Design View set to nothing (Null) instead of being
set to zero?
 
S

Stu

Golfinray, setting default value to "= is null" gave me an error.
tina, pushing the help button wasn't much help.

I'll go with this...it does what I want

Me.MinReg.SetFocus
Me.MinReg.Text = ""
 
D

Douglas J. Steele

"" and Null are not the same thing.

Null means unknown. "" means the value is known, and it doesn't exist.
 
S

Stu

Good point. Although I resolved the problem, the question is still there. If
I really needed a null, what's the code? Me.MinReg = ????
 
D

Dirk Goldgar

Stu said:
Good point. Although I resolved the problem, the question is still there.
If
I really needed a null, what's the code? Me.MinReg = ????


It's a strange request -- why have a default value defined in the table
design, but force it to Null in the form? -- but here goes ...

You can't rely on the form control's Default Value property alone. You can
set that property to "Null" (entered without the quotes in the property
sheet), and that will prevent the default value of 0 from being displayed on
a new record *until* you begin typing in the record. Then, code
intervention, the table's default value will appear in the control, and will
be saved when you save the record, unless you clear it.

So what you must also do is create an event procedure for the form's
BeforeInsert event, and in that procedure set the control's value to Null.
Like this:

Private Sub Form_BeforeInsert(Cancel As Integer)

Me.MinReg = Null

End Sub

In the quick test I just made, this worked.
 

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