Using .setfocus with afterupdate 
Author Message
 Using .setfocus with afterupdate

Getyongrooveon,

Had a lot of trouble with this myself (and still haven't figured it out).
Read a lot of the threads on Google on this subject and there's really
no easy way around it. You might try reading the Google threads
yourself.
http://www.*-*-*.com/

On way (depending on how elaborate your userform is)
Bring up your msgbox
Save all your entries to public variables
Unload and reshow the userform
Repopulate what you saved
Select any control that you want

I'm sure there's a better way.
Would be nice if it worked the way one would expect it to but
it doesn't.

John

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]



Sat, 16 Apr 2005 09:32:36 GMT  
 Using .setfocus with afterupdate
Can you use the _exit instead, with cancel=true?

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "You have entered something, I will now clear it")
Cancel = True
TextBox1.Text = ""
End Sub

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]

--

Dave Peterson



Sat, 16 Apr 2005 10:24:03 GMT  
 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]



Sat, 16 Apr 2005 16:18:57 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. setfocus of a textbox AfterUpdate

2. SetFocus Problem + AfterUpdate Problem

3. AfterUpdate, SetFocus, and item receiving focus

4. Combo Boxes and Using AfterUpdate

5. Remove Spaces using AfterUpdate?

6. Should I be using beforeupdate or afterupdate ?

7. Fetching a value from table using AfterUpdate

8. Forms AfterUpdate Event using date

9. Using SetFocus in spreadsheet

10. Error Message when using SetFocus


 
Powered by phpBB® Forum Software © phpBB Group