Setting controls

Gary_Mc_Mahon

Board Regular
Joined
Apr 30, 2003
Messages
87
Hi,
I'm trying to run a validation event on exit of a control. I've got 95% of the way there, just need a pointer on the finishing touches. I want the cursor to be in the actual field after the event. I cant seem to get the focus right. Here's what I have so far.

Private Sub Susp_Date_Time_triggered_Exit(Cancel As Integer)
'Validation of date entry
If Forms!Frm_Account_Screen![Susp Date/Time triggered] < Forms!Frm_Account_Screen![Date/Time Submitted] Or Forms!Frm_Account_Screen![Susp Date/Time triggered] < Forms!Frm_Account_Screen![Date Received] Then
MsgBox "Invalid date entry, please re enter date.", vbCritical, "Invalid Data"
Forms!Frm_Account_Screen![Susp Date/Time triggered] = ""
Screen.ActiveControl.SetFocus
Else
End If

End Sub

I'm stuck on screen.activecontrol.setfocus, any help??

Cheers,
Gary
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Instead of

Screen.ActiveControl.Setfocus

put

Cancel = TRUE

As far as as I know this 'cancels' the exit event so focus should remain in the control.
 
Upvote 0
Is the If statement actually working?

What type of control is it?

I think this might cause a problem:

Forms!Frm_Account_Screen![Susp Date/Time triggered] = ""


I've just done a small test of my suggested method and it worked fine, the cursor was placed back in at the start of the textbox, when I had entered something.

However when I left the textbox blank it continued on.

So you setting it blank may be the problem.
 
Upvote 0

Forum statistics

Threads
1,221,805
Messages
6,162,074
Members
451,738
Latest member
gaseremad

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