Date Validation in Text Box

melewie

Board Regular
Joined
Nov 21, 2008
Messages
188
Office Version
  1. 365
Platform
  1. Windows
Hi all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I am having problems with this have read a few threads but cant seem to get it to work I have a textbox on a user form and I want to make sure the date is in dd/mm/yy. If it isn’t I want a msg box to tell the user off!<o:p></o:p>
<o:p></o:p>
Any ideas appreciated.<o:p></o:p>
<o:p></o:p>
Thanks in advance.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Forget the format, and just test or a date

Code:
Private Sub TextBox1_AfterUpdate()
    With Me.TextBox1
    
        If Not IsDate(.Text) Then
    
            MsgBox "Invalid date"
        Else
        
            .Text = Format(CStr(.Text), "dd/mm/yyyy")
        End If
    End With
        
End Sub
 
Upvote 0
Thats what I did to start with but the "users" want to enter the dates manually and have a calander!!!!
 
Upvote 0
Forget the format, and just test or a date

Code:
Private Sub TextBox1_AfterUpdate()
    With Me.TextBox1
 
        If Not IsDate(.Text) Then
 
            MsgBox "Invalid date"
        Else
 
            .Text = Format(CStr(.Text), "dd/mm/yyyy")
        End If
    End With
 
End Sub

wish I read this a few mins ago just made up a random thing wich seems to work but is slightly over the top
Code:
If (Not IsDate(FRM_managers_additional_access.tbox_date_recived.Value) Or _
    Mid(FRM_managers_additional_access.tbox_date_recived.Value, 3, 1) <> "/" Or _
    Mid(FRM_managers_additional_access.tbox_date_recived.Value, 6, 1) <> "/" Or _
    Len(FRM_managers_additional_access.tbox_date_recived.Value) <> 8) Then
MsgBox "Enter date in Format dd/mm/yyyy"
Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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