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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » If..Then on textbox contents (Access 2003 SP2)

    Author
    Topic
    #443217

    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 [tComment]. I would like to be able to use an If…Then or Case statement to review the contents of [tComment]. If [tComment] has text then I want to make set a Label Control to visible (Me.lblSplat.Visible=True). However, if [tComment] 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:

         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
    

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

    Viewing 0 reply threads
    Author
    Replies
    • #1068617

      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.

      • #1068619

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

    Viewing 0 reply threads
    Reply To: If..Then on textbox contents (Access 2003 SP2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: