Default value code using VB

kabir_hussein

Registered User.
Local time
Today, 09:32
Joined
Oct 17, 2003
Messages
191
Hi

this is very easy i guess but i am no good at VB codes


i am trying to make a text box contain a default value using VB. If the text box contains no data i want the default value to be 0

any ideas

many thanks advance
 
Without using VBA you could set the "Default Value" property of the text box to 0 [zero].

Or, use the forms BeforeUpdate event and set the value to zero if the text box = Null.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(YourTextBox) Or YourTextBox = "" Then
        YourTextBox = 0
    Else
        'do nothing
    End If
End Sub
HTH
 
Last edited:
Hi i tried your code and it doesnt seem to work for some reason. the text box i am trying to make a defualt value if null is in the subform

here is the code i am using nevertheless

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Text22) Or Text22 = "" Then
Text22 = 0
Else
'do nothing
End If
End Sub


I have attached a screen shot

many thanks in advance

kabir
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    48.9 KB · Views: 245
Hi

i have tried to set the default value on the property sheet to 0, zero etc but it does not work

the text box is one i have created on the form purely for calcuations purposes. it does not belong to a table.

How it works is when users update an order sheet they text box calculates how many has been delivered - the quantity ordered.

I used the default value (on the property box) first but it did not work as i hoped.
 
All you want to use in your expression is the Nz() function - there's no need to make it difficult.

i.e.

=[Text1]+Nz([Textbox1],0)
 

Users who are viewing this thread

Back
Top Bottom