Handling Nulls in a String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jl2886
    New Member
    • Mar 2007
    • 83

    #1

    Handling Nulls in a String

    I have a button that when pressed on a form, automatically reads statments and inputs a text sentence, based on other fields on the form. However, the variable only gets assigned a sentence if something is true, but null if it is not true. The below code sits after all of the criteria statements. The problem is that when the first four statements are null, the field has four spaces before the sentence. This is obvious because of the " " after ever variable. Is there an automatic function that only read a space if the previous variable is not null, or do I have to make an isnull statement for every " ".

    [code]Me.Pending_Reas ons = NoLE & " " & updttfs & " " & updtavs & " " & Illno & " " & updtfas & " " & updtmidl & " " & updtisc & " " & SurNoLE & " " & surupdtfs & " " & surupdtmidl & " " & surupdtemsi & " " & surupdtavs & " " & surupdtfas & " " & surupdtisc[code/]
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    I've moved your question to the Access forum, thus it's visible by more experts.

    For conditional filling you can use an IF statement, but also the "+" character instead of the "&".
    When a Null value is attached to the string with a "+", then the whole string will be "nullified" .

    Thus you can use:
    varible = "Name " & "middlename " + " " & ....

    Nic;o)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Nice one Nico - Thanks. I never knew that :)

      Comment

      Working...