
Using .setfocus with afterupdate
Hi,
I use some time this :
TextBox_firstday.SetFocus
TextBox_firstday.SelStart = 0
TextBox_firstday.SelLength = Len(TextBox_firstday.Text)
this way, the text is selected and new input will clear the text.
For your first problem, check the other controls on the userform :
if the property "Tabstop" set to false for other controls that could take
focus.
TakeFocusOnClick ?
What is important :to realise what control has the focus and which clic
event triggers what.
If you set the above mentionned properties to false, then you can decide
yourself where to set the focus.
Regards,
Jean-Yves
Quote:
> I am having a problem with the textbox.setfocus control when linking the
> code to an afterupdate event for a textbox.
> Example:
> On a userform with two textboxs, using the following code:
> Private Sub TextBox1_AfterUpdate()
> MsgBox ("You have entered something, I will now clear it for you to enter
> something else")
> TextBox1.Text = ""
> TextBox1.SetFocus
> End Sub
> After you enter something in textbox and press enter the message box
> appears, on clicking OK the contents of textbox1 is cleared, but the focus
> is not returned to textbox1, but stays on textbox2.
> I have tried this in Excel 2000 and 2002 with the same results. Any ideas
> how I can set the focus back to textbox1 after the afterupdate event has
> triggered?
> AndyW
> [remove the "remove this bit" to reply direct]