Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

OFF2000: Exit Event for TextBox in a Frame Does Not Run Correctly


View products that this article applies to.

This article was previously published under Q210734

↑ Back to the top


Symptoms

The exit event for a TextBox control does not run when you click another control on your UserForm, or the exit event runs after the UserForm closes.

↑ Back to the top


Cause

This problem occurs when you add a TextBox control to a Frame in a UserForm, and you assign an exit event to the TextBox. The exit event will run at the correct time only when you click another control within the Frame.

↑ Back to the top


Workaround

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To run the exit event for the TextBox control, put the focus back onto a different control within the Frame. To do this, use the SetFocus method of any other control inside the Frame.

The macro example below illustrates how to run an exit event for TextBox1 when TextBox1 is within a Frame, and CommandButton1 is outside the Frame. When TextBox1 has the focus and you click CommandButton1, the exit event for the TextBox runs before the message box in CommandButton1_Click appears. If you do not shift the focus to Frame1, the exit event for TextBox1 runs after the message box for CommandButton1_Click appears.

This example assumes a UserForm that contains a Frame control, two TextBox controls inside the Frame, and a CommandButton control outside the Frame.
Private Sub CommandButton1_Click()
    TextBox2.SetFocus
    MsgBox "Button Click"
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    MsgBox "Box 1 exit"
End Sub
				

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

When a UserForm contains a Frame with one or more TextBox controls that contain exit events, the events do not run at the correct time when you click outside the Frame. For example, consider a UserForm that contains two TextBox controls, TextBox1 and TextBox2, within a Frame1 control, and a CommandButton1 outside the Frame. The exit event for TextBox1 does not run when you click CommandButton1. To correct this problem, set the focus to TextBox2 in your CommandButton1_Click subroutine, as illustrated in the "Workaround" section of this article.

↑ Back to the top


Keywords: kbbug, kbdtacode, kbnofix, kbprogramming, KB210734

↑ Back to the top

Article Info
Article ID : 210734
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 498