Userform Textbox date confirm

cerins4ever

New Member
Joined
Jun 5, 2014
Messages
35
Hi guys!
I have problem with data entry in text box.
I wanto to entry date lika 08.09.2014 or 08/09/2014, but if i entry other info. lika text abd or number 12.5 i need to textbox show that i have wrong info.

I have code wich work only with numbers but not with date

Code:
Private Sub TextBox7_Change()    If TypeName(Me.ActiveControl) = "TextBox" Then
        With Me.ActiveControl
        
            If Not IsDate(.Text) And .t <> vbNullString Then


                MsgBox "Sorry, only numbers allowed"


                .Value = vbNullString


            End If


        End With


    End If
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] TextBox7_Exit([color=darkblue]ByVal[/color] Cancel [color=darkblue]As[/color] MSForms.ReturnBoolean)
    [color=darkblue]With[/color] Me.TextBox7
        [color=darkblue]If[/color] Len(.Value) [color=darkblue]Then[/color]
            .Value = Replace(.Value, ".", "/")
            [color=darkblue]If[/color] [color=darkblue]Not[/color] IsDate(.Value) [color=darkblue]Then[/color]
                MsgBox "Please enter a valid date. ", vbExclamation, "Invalid Entry"
                Cancel = [color=darkblue]True[/color] [color=green]'cancel textbox exit[/color]
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Thanks a lot AlphaFrog you help me a lot, code is working.
Only now i need to figure out how to format amercian date to Euro date.
Thank you!
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

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