Consulting

Results 1 to 2 of 2

Thread: Validating more than one textbox for Null values

  1. #1
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    5
    Location

    Validating more than one textbox for Null values

    Hello All,

    I have working code to check a textbox for null values, etc. however I am not certain how to implement this code for let's say 5 textboxes. Any advice will be greatly appreciated.

    [VBA]Private Sub CommandButton1_Click()

    If Trim(textBox1 & "") = vbNullString Then
    MsgBox "Please Enter a numerical value in textBox1"
    Else
    Range("myCell") = ">" & Me.textBox1.Value
    End If
    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Private Sub CommandButton1_Click()
    Dim msg As String

    If Trim(TextBox1.Text) = vbNullString Then
    msg = "TextBox1"
    Else
    Range("myCell") = ">" & Me.TextBox1.Value
    End If

    If Trim(TextBox2.Text) = vbNullString Then
    msg = "TextBox2"
    Else
    Range("myCell") = ">" & Me.TextBox2.Value
    End If

    If Trim(TextBox3.Text) = vbNullString Then
    msg = "TextBox3"
    Else
    Range("myCell") = ">" & Me.TextBox3.Value
    End If

    If Trim(TextBox4.Text) = vbNullString Then
    msg = "TextBox4"
    Else
    Range("myCell") = ">" & Me.TextBox4.Value
    End If

    If Trim(TextBox5.Text) = vbNullString Then
    msg = "TextBox5"
    Else
    Range("myCell") = ">" & Me.TextBox5.Value
    End If

    If msg <> "" Then

    MsgBox "Please enter a numerical value in the following: " & vbNewLine & msg, vbInformation, "Incomplete data"
    End If
    End Sub
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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