I am designing a data input form which I have developed so far:
Private Sub OKButton_Click()
'Find the next row of the data sheet
NEXTROW = Worksheets("Bank Payment").Cells(Rows.Count, 1).End(xlUp).Row + 1
'Transfer data from ExpenseClassificationForm to worksheet
With Worksheets("Bank Payment")
.Cells(NEXTROW, 1).ClearFormats
On Error GoTo DateValidation
.Cells(NEXTROW, 1).Value = CDate(Me.DateText)
On Error GoTo 0
DateValidation:
MsgBox Prompt:="No date is entered for this transaction,Click on OK to continue or Click on Cancel to enter a date", Buttons:=vbOKCancel, Title:="Hashiru Chartered Certified Accountants"
If vbOK Then Me.DateText.SetFocus
End Sub
I am anticipating mistakes by users in inputting the date e.g. inputing text instead of valid date which is the only thing accepted by CDate(Me.DateText).
The error handling gives a message box and when OK (vbOK) is clicked on the message box, I want the DateText (which is the text box for the date) to be set focus to allow re-inputting of proper date.
Thanks for your help in advance.
Private Sub OKButton_Click()
'Find the next row of the data sheet
NEXTROW = Worksheets("Bank Payment").Cells(Rows.Count, 1).End(xlUp).Row + 1
'Transfer data from ExpenseClassificationForm to worksheet
With Worksheets("Bank Payment")
.Cells(NEXTROW, 1).ClearFormats
On Error GoTo DateValidation
.Cells(NEXTROW, 1).Value = CDate(Me.DateText)
On Error GoTo 0
DateValidation:
MsgBox Prompt:="No date is entered for this transaction,Click on OK to continue or Click on Cancel to enter a date", Buttons:=vbOKCancel, Title:="Hashiru Chartered Certified Accountants"
If vbOK Then Me.DateText.SetFocus
End Sub
I am anticipating mistakes by users in inputting the date e.g. inputing text instead of valid date which is the only thing accepted by CDate(Me.DateText).
The error handling gives a message box and when OK (vbOK) is clicked on the message box, I want the DateText (which is the text box for the date) to be set focus to allow re-inputting of proper date.
Thanks for your help in advance.