Textbox lostfocus event 
Author Message
 Textbox lostfocus event

Hello.  I am using the lostfocus events of the text boxes on my form for
validation purposes.  It turns out that if you click on another control like
a command button or a combo box, thereby losing focus on the text box, the
click event of that other control is not triggered and it only goes through
the lostfocus event of the textbox.  I've also found that if I click on the
toolbar of the same form,  it does go through the buttonclick event of my
toolbar but does not go through the lostfocus event of the textbox.

I need both event to be performed.  Help!!!

Gennie Marasigan



Tue, 27 Feb 2001 03:00:00 GMT  
 Textbox lostfocus event
Gennie,

I think you may need to give more details.  For me, using a form with one
text box and one command button (VB5) it works as expected - the lost focus
event firing and then the click event.

With a combo box it also appears to work, although the click event on a
combo box is fired when an item is selected in the list, not when it gets
the focus via a mouse click.  To trap on that event you need to trap on the
GotFocus event.

Regarding the toolbar, I think you will find that the toolbar cannot take
the focus, and thus the focus is left on the text box and the LostFocus
event is not triggered.  This can easily be gotten around by having the
toolbar explicitly call the LostFocus event as in Text1_LostFocus.

If you don't know what text box has the focus, there are several strategies
you could consider.  Probably the easiest one arises if there is a text box
that you can safely switch focus to (i.e. one that doesn't have any
validation).  Assume it is called Text2.  You can then proceed as follows:

Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
  Dim c As Control

  Set c = Me.ActiveControl
  Text2.SetFocus        ' Triggers the lost focus event of active control
  c.SetFocus
  Set c = Nothing
    ' Your code
End Sub

HTH

Peter

Quote:

>Hello.  I am using the lostfocus events of the text boxes on my form for
>validation purposes.  It turns out that if you click on another control
like
>a command button or a combo box, thereby losing focus on the text box, the
>click event of that other control is not triggered and it only goes through
>the lostfocus event of the textbox.  I've also found that if I click on the
>toolbar of the same form,  it does go through the buttonclick event of my
>toolbar but does not go through the lostfocus event of the textbox.

>I need both event to be performed.  Help!!!

>Gennie Marasigan



Wed, 28 Feb 2001 03:00:00 GMT  
 Textbox lostfocus event
Gennie,

a) No combobox click -- I suspect you are showing a MsgBox in the textbox
Lostfocus event? This swallows unprocessed Windows messages, so you lose the
click which caused the focus to be lost.

b) Toolbars are like menus -- they shouldn't get focus, and therefore they
shouldn't take it from the control which had focus at the time.

Advice: You should try to avoid using the LostFocus event if you possibly
can. Do your validation at the form level rather than the individual field
level. Use the Change event of the textbox (or similar events in other
controls) to enable and disable dependent controls.

If you are able to move to VB6, this provides a new mechanism, including a
Validate event, to avoid some of the problems you have found.

Bertie

Quote:

>Hello.  I am using the lostfocus events of the text boxes on my form for
>validation purposes.  It turns out that if you click on another control
like
>a command button or a combo box, thereby losing focus on the text box, the
>click event of that other control is not triggered and it only goes through
>the lostfocus event of the textbox.  I've also found that if I click on the
>toolbar of the same form,  it does go through the buttonclick event of my
>toolbar but does not go through the lostfocus event of the textbox.

>I need both event to be performed.  Help!!!



Fri, 02 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB Grid RowColChange Event Vs TextBox LostFocus Event

2. Can't get the LostFocus event jumping from TextBox to MSFlexGrid

3. use validate event to replace lostfocus event

4. LostFocus with forms and arrays for textboxes

5. Textboxes, Lostfocus And Command Buttons

6. Simply question about lostfocus, textbox and validate data!

7. Problem with Textbox lostfocus

8. Textbox LostFocus

9. Lostfocus of a textbox

10. Help on Leave & LostFocus Event

11. Problem with Focus and LostFocus Events

12. Validating, Validated, LostFocus Event Order

 

 
Powered by phpBB® Forum Software