Userform: Check if textbox is empty

fboehlandt

Active Member
Joined
Sep 9, 2008
Messages
334
Hi everyone,
I have a question regarding userforms. I have a commandbutton on a userform that is currently disabled. Above are four textboxes. The commandbutton should only be enabled if all four textboxes contain something (i.e. are not empty). How do I check fo rthat using VBA?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Never mind, this seems to work...

Code:
Private Sub TextBox_lastname_Change()
    CommandButton_proceed1.Enabled = False
    AllText
End Sub
Private Sub TextBox_firstname_Change()
    CommandButton_proceed1.Enabled = False
    AllText
End Sub
Private Sub TextBox_position_Change()
    CommandButton_proceed1.Enabled = False
    AllText
End Sub
Private Sub TextBox_fees_Change()
    OnlyNumbers
End Sub
Private Sub TextBox_serviceline_Change()
    CommandButton_proceed1.Enabled = False
    AllText
End Sub
Private Sub TextBox_projectcode_Change()
    CommandButton_proceed1.Enabled = False
    AllText
End Sub
Private Sub CommandButton_proceed1_Click()
    UserForm_Basic.Hide
    Load UserForm_Calendar
    UserForm_Calendar.Show
End Sub
Private Sub CommandButton_close1_Click()
    Unload Me
End Sub
Private Sub OnlyNumbers()
    If TypeName(Me.ActiveControl) = "TextBox" Then
        With Me.ActiveControl
            If Not IsNumeric(.Value) And .Value <> vbNullString Then
                MsgBox "Only numbers allowed!"
                .Value = vbNullString
            End If
        End With
    End If
End Sub
Private Sub AllText()
    If TextBox_lastname <> "" And _
    TextBox_firstname <> "" And _
    TextBox_position <> "" And _
    TextBox_serviceline <> "" And _
    TextBox_projectcode <> "" Then
        CommandButton_proceed1.Enabled = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top