Problem with the use of the method SetFocus Method

Hashiru

Active Member
Joined
May 29, 2011
Messages
286
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.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try

Code:
If MsgBox("No date is entered for this transaction,Click on OK to continue or Click on Cancel to enter a date", vbOKCancel, "Hashiru Chartered Certified Accountants") = vbOK Then Me.DateText.SetFocus
 
Upvote 0
Thanks for your reply.
That should have caused problem too. But this just ensure that if the date is correct the sub is exit. After the date I have to create severial other code lines to enter those values and details according to there criteria.
Thanks for that point.

I really want the code to direct the user to the textbox DateText so they can enter the correct date then.

:cool:Thanks
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top