I am trying to set a default value to a text box. I want to set default data like if textbox column is empty then return 0.
Is there any possible to set this in the textbox?
Thank you!
I am trying to set a default value to a text box. I want to set default data like if textbox column is empty then return 0.
Is there any possible to set this in the textbox?
Thank you!
Is the textbox bound to a field in a table?
Yes its linked to a query
to use the null textbox in a calculation use he nz function e.g.
linevalue=nz(txtprice,0) * nz(txtquantity,0)
will return 0 for linevalue if either txtprice or txtquantity is null
to display 0 in the field when it is null, use the control format property - put
#;#;0;0
if the field is a decimal number, then put
#.00;#.00;0.00;0.00
Thanks for the help Ajax. However, If I format the textbox, or the table it doesn't make the change on existing data.
Do you have any idea to change existing data as well as new data?
Thank you!
not clear what you are asking. There are only three choices
to set the default value to 0, you do so in the field or control properties (default value) - but this will only affect new records. If a user deletes a value in an existing record so the field is null, then it won't change to 0.
if an existing record has a null value you can format as I suggested
if you are using that value in a calculation, then you need to use the nz function as I suggested. Or you can use the nz function in your recordsource query - but then you will not be able to edit it.
only other option is to set the validation rule in the control or field to
is not null
which will prevent users from deleting a value to make it null
Note that changes to the field properties will not necessarily update existing control properties, so you may need to change there as well
Yes its linked to a query
A calculated textbox cannot be bound to anything, no?
A bit confusing: textboxes don't have columns, so is this really a textbox?
And why are you trying to calculate a value in a bound control - to store the calculation? That is a no-no (generally speaking).
The default value for a textbox is only meaningful for new records - it doesn't work for on existing records. If I understand you correctly, you want to make the value in textbox1 the same as textbox2, or 0 if textbox2 is Null.
You can do that in the On Current event of the form with : me![textbox1] = Nz(me!textbox2, 0)
Thanks guys for the help. I've decided to make another query for the calculation form.