Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If..Then on textbox contents (Access 2003 SP2)

    I have a textBox contol in the detail section of a report that displays a comment associated with the current record. The textBox is named <!t>[tComment]<!/t>. I would like to be able to use an If...Then or Case statement to review the contents of <!t>[tComment]<!/t>. If <!t>[tComment]<!/t> has text then I want to make set a Label Control to visible (Me.lblSplat.Visible=True). However, if <!t>[tComment]<!/t> is empty or null I want to leave the Label Control set to visible=False.

    When I use the following code, the Label Control is always set to True:
    <pre> Select Case Me.tComment.Text
    Case Is = " "
    Me.lblSplat.Visible = False
    Case Is = Null
    Me.lblSplat.Visible = False
    Case Else
    Me.lblSplat.Visible = True
    End Select
    </pre>



    Any suggestions on how to get only the <!t>[tComment]<!/t> fields that truly have a comment to turn the label on?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If..Then on textbox contents (Access 2003 SP2)

    You cannot compare to Null in a Select Case statement, because Null is not a value, but the absence of a value. Instead, do it like this:

    Me.lblSplat.Visible = Not IsNull(Me.tComment)

    Note: the Text property of a text box is only available if the text box has the focus, and it is a String property, so it is never Null.

  3. #3
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If..Then on textbox contents (Access 2003 SP2)

    Thank you very much Hans. That worked perfectly. I knew I was doing something wrong, but I rarely work with strings.

Posting Permissions

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