+ Reply to Thread
Results 1 to 2 of 2

check if multiple text boxes are empty

Hybrid View

randell.graybill check if multiple text boxes... 10-17-2009, 09:10 PM
D_Rennie Re: check if multiple text... 10-17-2009, 09:37 PM
  1. #1
    Forum Contributor
    Join Date
    04-03-2009
    Location
    USA, California
    MS-Off Ver
    Excel 2007
    Posts
    385

    check if multiple text boxes are empty

    What I need is some code to check if a few text boxes are empty, if the text box is empty then a message box should pop up that displays all which text boxes are empty and afterwards aborts the rest of the code.

    example:

    Company name: (Blank)
    Brand name: (Blank)
    cost: (Blank)

    after hitting submit a text box should pop up and inform the user that the above data is missing and stop the rest of the code from executing.

    below is the code I have however it does not stop the data that eventually gets added from being added to the spreadsheet
    If Not TextBox1.Value = vbNullString Then GoTo ttextbox2 Else MsgBox ("Please enter company name.")
    ttextbox2:
    If Not TextBox2.Value = vbNullString Then GoTo ttextbox3 Else MsgBox ("Please enter brand name.")
    ttextbox7:
    If Not TextBox7.Value = vbNullString Then GoTo ccombobox1 Else MsgBox ("Please enter bottle size")
    ccombobox1:
    If Not ComboBox1.Value = vbNullString Then GoTo ttextbox3 Else MsgBox ("Please enter if cases or eaches")
    ttextbox3:
    If Not TextBox3.Value = vbNullString Then GoTo ttextbox5 Else MsgBox ("Please enter how many bottles per case (if eaches enter 1)")
    ttextbox4:
    If Not TextBox4.Value = vbNullString Then GoTo tTextBox6 Else MsgBox ("Please enter comission percentage")
    ttextbox5:
    If Not TextBox5.Value = vbNullString Then GoTo tTextBox6 Else MsgBox ("Please enter cost")
    tTextBox6:
    If Not TextBox6.Value = vbNullString Then GoTo resumecode Else MsgBox ("Please enter selling price")
    resumecode:
    rest of the code

    Private Sub CommandButton1_Click()
    Call UnProtect_Sheet
    
    Application.Run "PERSONAL.XLS!Manual_Calculation"
    Application.Run "PERSONAL.XLS!Delete_Blank_ColumnA"
    
    
    
    If Not TextBox1.Value = vbNullString Then GoTo ttextbox2 Else MsgBox ("Please enter company name.")
    ttextbox2:
    If Not TextBox2.Value = vbNullString Then GoTo ttextbox3 Else MsgBox ("Please enter brand name.")
    ttextbox7:
    If Not TextBox7.Value = vbNullString Then GoTo ccombobox1 Else MsgBox ("Please enter bottle size")
    ccombobox1:
    If Not ComboBox1.Value = vbNullString Then GoTo ttextbox3 Else MsgBox ("Please enter if cases or eaches")
    ttextbox3:
    If Not TextBox3.Value = vbNullString Then GoTo ttextbox5 Else MsgBox ("Please enter how many bottles per case (if eaches enter 1)")
    ttextbox4:
    If Not TextBox4.Value = vbNullString Then GoTo tTextBox6 Else MsgBox ("Please enter comission percentage")
    ttextbox5:
    If Not TextBox5.Value = vbNullString Then GoTo tTextBox6 Else MsgBox ("Please enter cost")
    tTextBox6:
    If Not TextBox6.Value = vbNullString Then GoTo resumecode Else MsgBox ("Please enter selling price")
    resumecode:
    
    
    
    
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = Me.TextBox1.Value
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Me.TextBox2.Value
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = Me.TextBox7.Value
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 4).Value = Me.ComboBox1.Value
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Me.TextBox3.Value
    On Error GoTo exitsub
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 7).Value = Me.TextBox4.Value * (0.01)
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 5).Value = Me.TextBox5.Value
    Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(0, 6).Value = Me.TextBox6.Value
    
    Call Number_Format
    exitsub:
    
    Call Protect_Sheet
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: check if multiple text boxes are empty

    Hello,

    Probley not the prittiest way of going about it though it should work.
    If Me.TextBox1.Value = vbNullString Then
        MsgBox ("Please enter company name.")
        Exit Sub
    End If
    If Me.TextBox2.Value = vbNullString Then
        MsgBox ("Please enter brand name.")
        Exit Sub
    End If
    If Me.TextBox7.Value = vbNullString Then
        MsgBox ("Please enter bottle size")
        Exit Sub
    End If
    If Me.ComboBox1.Value = vbNullString Then
        MsgBox ("Please enter if cases or eaches")
        Exit Sub
    End If
    If Me.TextBox3.Value = vbNullString Then
        MsgBox ("Please enter how many bottles per case (if eaches enter 1)")
        Exit Sub
    End If
    If Me.TextBox4.Value = vbNullString Then
        MsgBox ("Please enter comission percentage")
        Exit Sub
    End If
    If Me.TextBox5.Value = vbNullString Then
        MsgBox ("Please enter cost")
        Exit Sub
    End If
    If Me.TextBox6.Value = vbNullString Then
        MsgBox ("Please enter selling price")
        Exit Sub
    End If
    hope it helps

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1