Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Posts
    20

    Unhappy Unanswered: trying to program - if null then equal to zero - help!

    Hello,

    I'm attempting to create a simple script that if the field is null will automatically reset the value of the field to zero -- I thought this code would work:

    Private Sub PriceAdjustment_AfterUpdate()

    If Me.[PriceAdjustment] = Null Then

    Me![PriceAdjustment] = 0

    End If

    End Sub

    If anybody sees the syntax mistake in this simple code, could you let me know what I'm doing wrong? Thanks in advance for your help!

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Comparing with null always results null.
    The statement something = null is never true.

    use the IsNull fuinction instead. In your case:

    if IsNull(Me.[PriceAdjustment]) then
    Me![PriceAdjustment] = 0
    end if

  3. #3
    Join Date
    Mar 2002
    Posts
    20
    I appreciate you clearing that up for me -- it works fine now!

    Thanks again!

  4. #4
    Join Date
    May 2002
    Posts
    4
    You can also use the Nz function

    Me.[PriceAdjustment] = Nz(Me.[PriceAdjustment] )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •