Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default AfterUpdate/BeforeUpdate and SetFocus

I have some problems with the SetFocus command in a Userform with an
AfterUpdate or BeforeUpdate routine.

To make it clear to you, I made a very small Userform to demonstrate it. It
only contains 8 TextBoxes and this code:

Code:
Private Sub TextBox01_AfterUpdate()
Me.TextBox08.SetFocus
End Sub
-
Private Sub TextBox02_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
TextBox08.SetFocus
End Sub
-
Private Sub TextBox03_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox08.SetFocus
End Sub
-
Private Sub TextBox04_Change()
TextBox08.SetFocus
End Sub

I expected that in all cases, the focus should be set to TextBox08, but this
only happens with the Change event.

Do you have any suggestions how I can set the focus to TextBox08 in an
AfterUpdate or BeforeUpdate event?

I use Excel 2007

Kind regards,

Otto.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default AfterUpdate/BeforeUpdate and SetFocus

Hi Otto,

I believe that the problem you face is when the event takes place. Other
than change, the cursor has already moved to the next control before the
event fires. The change event takes place as soon as any change is made and
not necessarily after all changes have been made within the control. Example
change text to pest; change event takes place as soon as you type the p.

The following is one method of achieving your desired result. I am
interested in other solutions so I'll monitor this thread for any.

On the enter event sets all the tab stops to False and then sets the tab
stop of the desired next control to True. I have used 8 Text boxes and set
the tab stop to a different text box on each of the Enter events.

Private Sub TextBox01_Enter()
Call TabStopsFalse
Me.TextBox05.TabStop = True
End Sub

Private Sub TextBox02_Enter()
Call TabStopsFalse
Me.TextBox06.TabStop = True
End Sub

Private Sub TextBox03_Enter()
Call TabStopsFalse
Me.TextBox07.TabStop = True
End Sub

Private Sub TextBox04_Enter()
Call TabStopsFalse
Me.TextBox08.TabStop = True
End Sub

Sub TabStopsFalse()
Dim ctrl As Control
For Each ctrl In Controls
ctrl.TabStop = False
Next ctrl
End Sub


--
Regards,

OssieMac


"odekkers" wrote:

I have some problems with the SetFocus command in a Userform with an
AfterUpdate or BeforeUpdate routine.

To make it clear to you, I made a very small Userform to demonstrate it. It
only contains 8 TextBoxes and this code:

Code:
Private Sub TextBox01_AfterUpdate()
Me.TextBox08.SetFocus
End Sub
-
Private Sub TextBox02_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
TextBox08.SetFocus
End Sub
-
Private Sub TextBox03_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox08.SetFocus
End Sub
-
Private Sub TextBox04_Change()
TextBox08.SetFocus
End Sub

I expected that in all cases, the focus should be set to TextBox08, but this
only happens with the Change event.

Do you have any suggestions how I can set the focus to TextBox08 in an
AfterUpdate or BeforeUpdate event?

I use Excel 2007

Kind regards,

Otto.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Afterupdate problem with setfocus on a txtbox in a form [email protected] Excel Programming 2 February 6th 09 03:15 PM
beforeUpdate event of Web Query johnbest[_3_] Excel Programming 2 January 25th 06 01:37 PM
Form, SetFocus and AfterUpdate issue Piers 2k Excel Programming 2 November 8th 05 01:52 PM
BeforeUpdate and Cancel Brad Excel Programming 0 May 10th 04 09:06 PM
BeforeUpdate event for Combo box Brad Excel Programming 2 May 7th 04 06:22 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"