P
pilgrimm
I have a user form that works great but I have one last item to fix.
If someone types in a date wrong, it will not update the spreadsheet
with any info and does not give an option to fix the date. What I
would like is an error message and not to update the spreadsheet but
to be able to fix the date. Once that is done, click on OK and then
it can update sheet.
Here is what I have:
Private Sub OK_Click()
Dim RowCount As Long
If Me.txtName.Value = "" Then
MsgBox "Please enter Employee's name", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTPRI.Value = "" Then
MsgBox "Please enter Employee's PRI", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.CBODEPARTMENT.Value = "" Then
MsgBox "Please Choose a Department", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.cboPSHCPLEVEL.Value = "" Then
MsgBox "Please Choose PSHCP Level", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTDEDUCTIONDATE.Value = "" Then
MsgBox "Please Enter a Deducton Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTCOVERAGEDATE.Value = "" Then
MsgBox "Please Enter a Coverage Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
RowCount =
Worksheets("PSHCP").Range("A1").CurrentRegion.Rows.Count
With Worksheets("PSHCP").Range("A1")
.Offset(RowCount, 7).Value = Format(Now, "dd/mmm/yyyy
hh:nn:ss") & Application.UserName
.Offset(RowCount, 0).Value = Me.txtName.Value
.Offset(RowCount, 1).Value = Me.TXTPRI.Value
.Offset(RowCount, 2).Value = Me.CBODEPARTMENT.Value
.Offset(RowCount, 3).Value = Me.cboPSHCPLEVEL.Value
.Offset(RowCount, 4).Value = DateValue(TXTDEDUCTIONDATE.Value)
.Offset(RowCount, 5).Value = DateValue(TXTCOVERAGEDATE.Value)
End With
Unload Me
End Sub
If someone types in a date wrong, it will not update the spreadsheet
with any info and does not give an option to fix the date. What I
would like is an error message and not to update the spreadsheet but
to be able to fix the date. Once that is done, click on OK and then
it can update sheet.
Here is what I have:
Private Sub OK_Click()
Dim RowCount As Long
If Me.txtName.Value = "" Then
MsgBox "Please enter Employee's name", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTPRI.Value = "" Then
MsgBox "Please enter Employee's PRI", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.CBODEPARTMENT.Value = "" Then
MsgBox "Please Choose a Department", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.cboPSHCPLEVEL.Value = "" Then
MsgBox "Please Choose PSHCP Level", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTDEDUCTIONDATE.Value = "" Then
MsgBox "Please Enter a Deducton Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTCOVERAGEDATE.Value = "" Then
MsgBox "Please Enter a Coverage Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
RowCount =
Worksheets("PSHCP").Range("A1").CurrentRegion.Rows.Count
With Worksheets("PSHCP").Range("A1")
.Offset(RowCount, 7).Value = Format(Now, "dd/mmm/yyyy
hh:nn:ss") & Application.UserName
.Offset(RowCount, 0).Value = Me.txtName.Value
.Offset(RowCount, 1).Value = Me.TXTPRI.Value
.Offset(RowCount, 2).Value = Me.CBODEPARTMENT.Value
.Offset(RowCount, 3).Value = Me.cboPSHCPLEVEL.Value
.Offset(RowCount, 4).Value = DateValue(TXTDEDUCTIONDATE.Value)
.Offset(RowCount, 5).Value = DateValue(TXTCOVERAGEDATE.Value)
End With
Unload Me
End Sub