Hello!
So in response to a previous question, I went ahead and made a User Form. However, the skills that I am lacking make this one thing quite difficult.
I created the form and used the Date to display an error if the text box associated with the Date was not entered in a specific format. The problem that I am having is that even though I got the error message to pop-up, the User Form still adds the data to the spreadsheet. Thus when then user clicks "Ok" and fixes the date, now there are 2 entries in the spreadsheet vice the one.
Is there a way to not allow the user to "save" the user form and add the data to the spreadsheet if the date is formatted incorrectly?
For example;
[TABLE="width: 500"]
<tbody>[TR]
[TD]Account[/TD]
[TD]Date[/TD]
[TD]Ref #[/TD]
[/TR]
[TR]
[TD]111[/TD]
[TD]abc[/TD]
[TD]123[/TD]
[/TR]
[TR]
[TD]111[/TD]
[TD]01/01/2018[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
So in response to a previous question, I went ahead and made a User Form. However, the skills that I am lacking make this one thing quite difficult.
I created the form and used the Date to display an error if the text box associated with the Date was not entered in a specific format. The problem that I am having is that even though I got the error message to pop-up, the User Form still adds the data to the spreadsheet. Thus when then user clicks "Ok" and fixes the date, now there are 2 entries in the spreadsheet vice the one.
Is there a way to not allow the user to "save" the user form and add the data to the spreadsheet if the date is formatted incorrectly?
For example;
[TABLE="width: 500"]
<tbody>[TR]
[TD]Account[/TD]
[TD]Date[/TD]
[TD]Ref #[/TD]
[/TR]
[TR]
[TD]111[/TD]
[TD]abc[/TD]
[TD]123[/TD]
[/TR]
[TR]
[TD]111[/TD]
[TD]01/01/2018[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Private Sub cmdbtnSave_Click()
Dim emptyRow As Long
'Make Sheet3 active
Sheet3.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
'Transfer information
Cells(emptyRow, 2).Value = combAccount.Value
Cells(emptyRow, 3).Value = txtDate.Value
Cells(emptyRow, 4).Value = txtRef.Value
Cells(emptyRow, 5).Value = txtPayee.Value
If optbtnYes.Value = True Then
Cells(emptyRow, 6).Value = "Yes"
Else
Cells(emptyRow, 6).Value = "No"
End If
Cells(emptyRow, 7).Value = combCategory.Value
Cells(emptyRow, 8).Value = txtMemo.Value
If combStatus.Value = "Reconciled" Then
Cells(emptyRow, 9).Value = "R"
Else
If combStatus.Value = "Cleared" Then
Cells(emptyRow, 9).Value = "C"
Else
Cells(emptyRow, 9).Value = "V"
End If
End If
If btnIncome.Value = False Then
Cells(emptyRow, 10).Value = txtIncome
Else
Cells(emptyRow, 11).Value = txtIncome
End If
If Not IsDate(Me.txtDate.Text) Then
MsgBox "The Data entered is not a Date" & Chr(10) & "Please Try again"
End If
End Sub