Show userform error message

dan_pafc

Board Regular
Joined
Aug 16, 2007
Messages
162
Hi

Im looking for a bit of code so that if textbox.1 from a userform is left blank when unloading the form, a msg appears with a warning, and doesn’t allow you to save unless all boxes are completed.

I have the following at the moment:

a = TextBox1.Text
If a = "" Then
MsgBox "You must enter your name"
End If
Range("D5").Select
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = a

Kind Regards,

Dan.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Put the test in the userform unload routine and don't unload it if it is not completed.
 
Upvote 0
Yeah, assuming that you have OK and Cancel buttons, then something like

Code:
Private Sub cmdCancel_Click()
    Me.Hide
End Sub

Private Sub cmdOK_Click()
    If Me.TextBox1.Text = "" Then
    
        MsgBox "You must enter your name"
    Else
        .... so your stuff here
        Me.Hide
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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