VBA Code:
Private Sub CommandButton1_Click()
Dim emptyRow As Long
TextBox4.Value = Format(TextBox4.Value, "MM/DD/YYYY")
TextBox5.Value = Format(TextBox5.Value, "MM/DD/YYYY")
If TextBox1.Value = "" Or TextBox2.Value = "" Or TextBox3.Value = "" Or TextBox4.Value = "" Or TextBox5.Value = "" Or TextBox7.Value = "" Then
MsgBox "TO ADD EMPLOYEE ALL FIELD WITH * MUSTH BE ENTERED", vbExclamation: Exit Sub
End If
If Not IsNumeric(TextBox1) Then MsgBox "INVALID EMPLOYEE NUMBER ENTER NUMBER WITHOUT THE E", vbExclamation:
TextBox1.SetFocus
Exit Sub
If Not IsDate(TextBox4) Then MsgBox "SLI DATE/DATE OF HIRE IS NOT INVALID DATE", vbExclamation:
TextBox4.SetFocus
Exit Sub
If Not IsDate(TextBox5) Then MsgBox "DATE OF BIRTH IS NOT INVALID DATE", vbExclamation:
TextBox5.SetFocus
Exit Sub
With ActiveSheet
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
Cells(emptyRow, 2).Value = TextBox1.Value
Cells(emptyRow, 3).Value = TextBox2.Value
Cells(emptyRow, 4).Value = TextBox3.Value
Cells(emptyRow, 14).Value = TextBox4.Value
Cells(emptyRow, 15).Value = TextBox5.Value
Cells(emptyRow, 20).Value = TextBox6.Value
Cells(emptyRow, 22).Value = TextBox7.Value
End With
End Sub
using the UserForm I'm trying to accomplish an error code if the value in textbox4 or textbox5 are not "MM/DD/YYYY" format to generate an error message. any help is greatly appreciate.