Results 1 to 9 of 9
  1. #1
    Jaik is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    33

    how can I set up text box if value is null then 0?


    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!

  2. #2
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    Is the textbox bound to a field in a table?

  3. #3
    Jaik is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    33
    Yes its linked to a query

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    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

  5. #5
    Jaik is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    33
    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!

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    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

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    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).

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    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)

  9. #9
    Jaik is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    33
    Thanks guys for the help. I've decided to make another query for the calculation form.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Null parameter text in report title
    By Beeblebrox in forum Reports
    Replies: 3
    Last Post: 06-19-2016, 11:10 AM
  2. Removing Text If Null
    By lewis1682 in forum Reports
    Replies: 1
    Last Post: 09-23-2013, 10:46 AM
  3. VBA to update to predefined text where is null
    By webisti in forum Programming
    Replies: 1
    Last Post: 12-05-2012, 02:13 PM
  4. how to deal with null time value in text box
    By RedGoneWILD in forum Programming
    Replies: 5
    Last Post: 06-28-2012, 06:56 PM
  5. Replies: 21
    Last Post: 05-20-2012, 02:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums