Prevent loss of focus in Exit Event

mgw1138

New Member
Joined
Mar 9, 2014
Messages
33
Private Sub CB_Day_Exit(ByVal Cancel As MSForms.ReturnBoolean)
....
.....
If Int(CB_Day.Value) > DaysInMonth Then
CB_Day.SetFocus
CB_Day = ""
Exit Sub
Else
"Cells(17, 12) = DateSerial(Int(CB_Year.Value), m, Int(CB_Day.Value))
End If
End Sub

I have a textbox name CB_day. If CB_Month.Value = "September" the script will look up 30 as DaysInMonth. if CB_Month.Value is more the script does execute
the lines
CB_Day.SetFocus
CB_Day = ""

When the event completes however focus does pass to the next combo box. How do I prevent this. I understand that unlike Access the loss_focus is embedded in the OnExit.
What am I not understandying about the Exit event and the Setfocus command.

Thanks in Advance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Excellent - I did not find that in the description of the procedure. It has been perhaps 5 years since I have done VBA and it is scary how much I have forgotten and/or never knew.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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