If text box in userform is not empty then msgbox

Claire Jackson

Board Regular
Joined
Jun 30, 2020
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm using the following code but it isn't working? Basically I have a text box that requires a popup message to tell the user that he must do something if he has entered data in the text box

Sub RevisedDate()

If Txt_Rev_Comp_Date.Text.Value <> "" Then
MsgBox "I'm not empty!"
End If

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
hi claire , you have to choose value or text not together the code should be like this
VBA Code:
Sub RevisedDate()

If Txt_Rev_Comp_Date.Text <> "" Then
MsgBox "I'm not empty!"
End If
End Sub
or this
Code:
Sub RevisedDate()

If Txt_Rev_Comp_Date.Value <> "" Then
MsgBox "I'm not empty!"
End If

End Sub
 
Upvote 0
OK thanks, I've tried both and it's not showing me the message box? it's just letting me type a date in and then just tabbing to the next field
 
Upvote 0
Claire

How are you executing RevisedDate?

Are you calling it from the Exit event of the Txt_Rev_Comp_Date textbox or some other event?
 
Upvote 0
i hope this help

VBA Code:
Private Sub  If Txt_Rev_Comp_Date_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Txt_Rev_Comp_Date = vbNullString Then Exit Sub
If IsDate(Txt_Rev_Comp_Date) Then
Txt_Rev_Comp_Date = Format(Txt_Rev_Comp_Date, "dd/mm/yyyy")
MsgBox "I'm not empty!"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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