Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi, good afternoon, i have the code below, where if i enter a date into the text box like 121219 or 12122019 it should convert to 12/12/2019 but it doesn't it either says date incorrect or change it to 23/23/2023 which is wrong, please can you help.
Code:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim dtTmp As Date
Cancel = False
On Error GoTo err_baddate
dtTmp = CDate(Me.TextBox1.Text)
Me.TextBox1.Text = dtTmp
On Error GoTo 0
sub_ex:
Exit Sub
err_baddate:
MsgBox "Bad date", vbOKOnly + vbExclamation
Cancel = True
Resume sub_ex
End Sub