Hello
i am getting Msgbox Error Twice when i close the userform
Can someone check and help me to get rid of the MsgboxError when i close the userform
Basically if the date is wrong for which
I puroposely incorporated Cancel = True in the If EndIf so that textbox1 is set focussed
but when i close the userform after the executing the above. The msgbox Error is displayed not once but Twice
if the date is right and closing the userform then no message
Code in Userform
Thanks NimishK
i am getting Msgbox Error Twice when i close the userform
Can someone check and help me to get rid of the MsgboxError when i close the userform
Basically if the date is wrong for which
I puroposely incorporated Cancel = True in the If EndIf so that textbox1 is set focussed
but when i close the userform after the executing the above. The msgbox Error is displayed not once but Twice
if the date is right and closing the userform then no message
Code in Userform
Code:
Option Explicit
Public dDate As Date
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Mid(TextBox1.Value, 4, 2) > 12 Then
Cancel = True
MsgBox "Invalid date, please re-enter", vbCritical
TextBox1.Value = vbNullString
TextBox1.SetFocus
Exit Sub
End If
dDate = DateSerial(Year(Date), Month(Date), Day(Date))
TextBox1.Value = Format(CDate(TextBox1.Value), "dd-mmm-yyyy")
End Sub
Last edited: