PC Review


Reply
Thread Tools Rate Thread

AfterUpdate/BeforeUpdate and SetFocus

 
 
odekkers
Guest
Posts: n/a
 
      5th May 2010
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 With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      5th May 2010
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnChange or BeforeUpdate or AfterUpdate event? PayeDoc Microsoft Access Forms 2 11th Mar 2009 03:56 PM
BeforeUpdate or AfterUpdate ? W Microsoft Access Form Coding 11 9th Jan 2008 10:22 PM
BeforeUpdate or AfterUpdate Events =?Utf-8?B?VGVk?= Microsoft Access Form Coding 4 25th Apr 2006 02:13 PM
BeforeUpdate or AfterUpdate? Gary Schuldt Microsoft Access Forms 10 20th Oct 2004 01:57 AM
Jumping for BeforeUpdate to AfterUpdate Matt Microsoft Access Form Coding 1 17th Aug 2004 10:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 AM.