I am using VB6 for maintenance of this program and have an odd behavior thet
I can't seem to get a handle on.
I have a routine in the LostFocus event for a combobox which will verify
that the value has changed from the original. If a change is noted it will
produce a msgbox asking for verification. If a change is made and a textbox
or some other control on the form is clicked the msgbox displays, accepts the
response, and moves focus to the item clicked.
If you click on a button or menu item the lostfocus event still fires (as I
don't believe it should) but it puts focus back on the combobox instead of
continuing on with the clicked button or menu item.
I have nothing in the lostfocus event which is setting the focus back to the
original control. Is there a setting that I am missing or something like
that?

Re: Interesting Lostfocus behavior by Saga

Saga
Mon Oct 13 13:43:07 CDT 2008

I would use the Validate event of the combobox instead of the lost focus and see
how that works out.

Saga
--


"SLink9" <SLink9@discussions.microsoft.com> wrote in message
news:A913A1CA-062F-4EFC-B92D-49CE107E4FD8@microsoft.com...
>I am using VB6 for maintenance of this program and have an odd behavior thet
> I can't seem to get a handle on.
> I have a routine in the LostFocus event for a combobox which will verify
> that the value has changed from the original. If a change is noted it will
> produce a msgbox asking for verification. If a change is made and a textbox
> or some other control on the form is clicked the msgbox displays, accepts the
> response, and moves focus to the item clicked.
> If you click on a button or menu item the lostfocus event still fires (as I
> don't believe it should) but it puts focus back on the combobox instead of
> continuing on with the clicked button or menu item.
> I have nothing in the lostfocus event which is setting the focus back to the
> original control. Is there a setting that I am missing or something like
> that?



Re: Interesting Lostfocus behavior by SLink9

SLink9
Mon Oct 13 13:57:01 CDT 2008

That is what I had gathered was supposed to be the solution but that didn't
work either. I use that and the check fires but it will still either place
focus on the combobox or the button clicked but will not continue with button
click processiing. I am trying now to look at the control that had focus set
to it with screen.activecontrol but I am only getting values from it intead
of control names.

"Saga" wrote:

> I would use the Validate event of the combobox instead of the lost focus and see
> how that works out.
>
> Saga
> --
>
>
> "SLink9" <SLink9@discussions.microsoft.com> wrote in message
> news:A913A1CA-062F-4EFC-B92D-49CE107E4FD8@microsoft.com...
> >I am using VB6 for maintenance of this program and have an odd behavior thet
> > I can't seem to get a handle on.
> > I have a routine in the LostFocus event for a combobox which will verify
> > that the value has changed from the original. If a change is noted it will
> > produce a msgbox asking for verification. If a change is made and a textbox
> > or some other control on the form is clicked the msgbox displays, accepts the
> > response, and moves focus to the item clicked.
> > If you click on a button or menu item the lostfocus event still fires (as I
> > don't believe it should) but it puts focus back on the combobox instead of
> > continuing on with the clicked button or menu item.
> > I have nothing in the lostfocus event which is setting the focus back to the
> > original control. Is there a setting that I am missing or something like
> > that?
>
>
>

Re: Interesting Lostfocus behavior by SLink9

SLink9
Mon Oct 13 14:17:01 CDT 2008

Maybe a graphical layout will help us both to understand this one. I want to
click on a button, basically place the routine on hold while I process the
validate code, and then resume with the button processing.

----- process verification routine -----
/ \
button click -- wait for above routine -- Continue processing button click
code

If I were doing this in .net I believe that showdialog would provide this
functionality. I have not tried it since it won't matter for this app
anyway. It seems that the msgbox is taking focus and then it is not being
returned properly. Other suggestions?

"Saga" wrote:

> I would use the Validate event of the combobox instead of the lost focus and see
> how that works out.
>
> Saga
> --
>
>
> "SLink9" <SLink9@discussions.microsoft.com> wrote in message
> news:A913A1CA-062F-4EFC-B92D-49CE107E4FD8@microsoft.com...
> >I am using VB6 for maintenance of this program and have an odd behavior thet
> > I can't seem to get a handle on.
> > I have a routine in the LostFocus event for a combobox which will verify
> > that the value has changed from the original. If a change is noted it will
> > produce a msgbox asking for verification. If a change is made and a textbox
> > or some other control on the form is clicked the msgbox displays, accepts the
> > response, and moves focus to the item clicked.
> > If you click on a button or menu item the lostfocus event still fires (as I
> > don't believe it should) but it puts focus back on the combobox instead of
> > continuing on with the clicked button or menu item.
> > I have nothing in the lostfocus event which is setting the focus back to the
> > original control. Is there a setting that I am missing or something like
> > that?
>
>
>

Re: Interesting Lostfocus behavior by Ken

Ken
Mon Oct 13 14:38:36 CDT 2008

"SLink9" <SLink9@discussions.microsoft.com> wrote in message
news:7E093A5E-A8C0-4965-B0C1-129243A35DC6@microsoft.com...
> That is what I had gathered was supposed to be the solution but that
> didn't
> work either. I use that and the check fires but it will still either
> place
> focus on the combobox or the button clicked but will not continue with
> button
> click processiing. I am trying now to look at the control that had focus
> set
> to it with screen.activecontrol but I am only getting values from it
> intead
> of control names.

What you're seeing is the contents of that control's default property.

Use:

ActiveControl.Name 'to get the name
TypeName(ActiveControl) 'will give the control's type

If I'm reading correctly, this seems to do the job... uses a Timer to
disconnect the combo boxes event from "the world"
'===============
Option Explicit
'Needs:
'a Timer called tmrShiftFocus
'a ComboBox called Combo1
'a few more controls sprinkled around

Private mbIgnoreChange As Boolean
Private msComboText As String
Private miComboListIndex As Integer

Private Function DataChanged() As Boolean
If Not mbIgnoreChange Then
If msComboText = Combo1.Text Then
Me.Caption = "No Change " & Timer
Else
Me.Caption = "Last Change " & Timer
DataChanged = True
End If
End If
End Function

Private Sub Combo1_Click()
Call DataChanged
End Sub

Private Sub Combo1_Change()
Call DataChanged
End Sub

Private Sub Combo1_GotFocus()
msComboText = Combo1.Text
miComboListIndex = Combo1.ListIndex
Call DataChanged 'Just to update the display
End Sub

Private Sub Combo1_LostFocus()
tmrShiftFocus.Enabled = True
End Sub

Private Sub Form_Load()

mbIgnoreChange = True

With tmrShiftFocus
.Enabled = False
.Interval = 1
End With

With Combo1
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
.AddItem "Item 4"
.AddItem "Item 5"
.AddItem "Item 6"
.ListIndex = 0
.Tag = .Text
End With

mbIgnoreChange = False

End Sub

Private Sub tmrShiftFocus_Timer()
tmrShiftFocus.Enabled = False
If DataChanged Then
If MsgBox("Accept?", vbYesNo) = vbNo Then
Combo1.ListIndex = miComboListIndex
Combo1.Text = msComboText
Combo1.SetFocus
Else
ActiveControl.SetFocus
End If
End If
End Sub
'===============

--
Ken Halter
Part time groupie



Re: Interesting Lostfocus behavior by SLink9

SLink9
Mon Oct 13 14:46:01 CDT 2008

Since I can't seem to make VB6 behave as outlined in one of the replies to
this post I have placed code in the lostfocus of the combobox which
determines which item was clicked. It ten determines if a commandbutton was
clicked. If a commandbutton was clicked I want to run the _click routine for
it. I just thought of using with although I am unsure of how this will work
in VB6. Here is the code.

Dim curritm
curritm = Screen.ActiveControl.Name
If TypeOf Screen.ActiveControl Is CommandButton Then
'Screen.ActiveControl.Name_Click
End If

I am going to change the commented line to have

with curitm
_click

I don't believe that will work. Any suggestions for getting this
implemented? Better direction?

"Saga" wrote:

> I would use the Validate event of the combobox instead of the lost focus and see
> how that works out.
>
> Saga
> --
>
>
> "SLink9" <SLink9@discussions.microsoft.com> wrote in message
> news:A913A1CA-062F-4EFC-B92D-49CE107E4FD8@microsoft.com...
> >I am using VB6 for maintenance of this program and have an odd behavior thet
> > I can't seem to get a handle on.
> > I have a routine in the LostFocus event for a combobox which will verify
> > that the value has changed from the original. If a change is noted it will
> > produce a msgbox asking for verification. If a change is made and a textbox
> > or some other control on the form is clicked the msgbox displays, accepts the
> > response, and moves focus to the item clicked.
> > If you click on a button or menu item the lostfocus event still fires (as I
> > don't believe it should) but it puts focus back on the combobox instead of
> > continuing on with the clicked button or menu item.
> > I have nothing in the lostfocus event which is setting the focus back to the
> > original control. Is there a setting that I am missing or something like
> > that?
>
>
>

Re: Interesting Lostfocus behavior by Ken

Ken
Mon Oct 13 15:57:49 CDT 2008

"SLink9" <SLink9@discussions.microsoft.com> wrote in message
news:97B39414-A4E2-45C3-9879-9153106F682E@microsoft.com...
> it. I just thought of using with although I am unsure of how this will
> work
> in VB6. Here is the code.
> Dim curritm
> curritm = Screen.ActiveControl.Name

Well, first of all, you'd need to use Set curritm = Screen.ActiveControl,
but it'll get ugly.

> I am going to change the commented line to have
>
> with curitm
> _click

Absolutely will not work. " _click" is not a built in method/property...
while it /is/ an event, it won't show in intellisense unless there's code in
the event handler, and even then, it won't work with a With block... if you
tried my snip and weren't happy with that, you'll probably be stuck with
CallByName (and a bunch of grey or missing hair)

> I don't believe that will work. Any suggestions for getting this
> implemented? Better direction?

Did you try that snip I posted?



--
Ken Halter
Part time groupie



Re: Interesting Lostfocus behavior by Eduardo

Eduardo
Mon Oct 13 17:07:40 CDT 2008

"SLink9" <SLink9@discussions.microsoft.com> escribió en el mensaje
news:97B39414-A4E2-45C3-9879-9153106F682E@microsoft.com...
> Since I can't seem to make VB6 behave as outlined in one of the replies to
> this post I have placed code in the lostfocus of the combobox which
> determines which item was clicked. It ten determines if a commandbutton
> was
> clicked. If a commandbutton was clicked I want to run the _click routine
> for
> it. I just thought of using with although I am unsure of how this will
> work
> in VB6. Here is the code.
>
> Dim curritm
> curritm = Screen.ActiveControl.Name
> If TypeOf Screen.ActiveControl Is CommandButton Then
> 'Screen.ActiveControl.Name_Click
> End If

Try this:

If TypeOf Screen.ActiveControl Is CommandButton Then
Screen.ActiveControl.Value = 1
End If



Re: Interesting Lostfocus behavior by Bert

Bert
Tue Oct 14 06:14:06 CDT 2008

Couldn't it be that there is no other control
with a TabStop = True available?
It looks to me that the focus is unable to go
to another control after clicking the combo.
Bert.


"SLink9" <SLink9@discussions.microsoft.com> schreef in bericht
news:97B39414-A4E2-45C3-9879-9153106F682E@microsoft.com...
> Since I can't seem to make VB6 behave as outlined in one of the replies to
> this post I have placed code in the lostfocus of the combobox which
> determines which item was clicked. It ten determines if a commandbutton
> was
> clicked. If a commandbutton was clicked I want to run the _click routine
> for
> it. I just thought of using with although I am unsure of how this will
> work
> in VB6. Here is the code.
>
> Dim curritm
> curritm = Screen.ActiveControl.Name
> If TypeOf Screen.ActiveControl Is CommandButton Then
> 'Screen.ActiveControl.Name_Click
> End If
>
> I am going to change the commented line to have
>
> with curitm
> _click
>
> I don't believe that will work. Any suggestions for getting this
> implemented? Better direction?
>


Re: Interesting Lostfocus behavior by SLink9

SLink9
Tue Oct 14 06:57:01 CDT 2008

Eduardo,

That worked beautifully for the command button. o you have a suggestion for
processing a cListBar click? That is the other option for a click in this
case and checking for a type of cListBar or cListBarItem does not trigger.

"Eduardo" wrote:

> "SLink9" <SLink9@discussions.microsoft.com> escribió en el mensaje
> news:97B39414-A4E2-45C3-9879-9153106F682E@microsoft.com...
> > Since I can't seem to make VB6 behave as outlined in one of the replies to
> > this post I have placed code in the lostfocus of the combobox which
> > determines which item was clicked. It ten determines if a commandbutton
> > was
> > clicked. If a commandbutton was clicked I want to run the _click routine
> > for
> > it. I just thought of using with although I am unsure of how this will
> > work
> > in VB6. Here is the code.
> >
> > Dim curritm
> > curritm = Screen.ActiveControl.Name
> > If TypeOf Screen.ActiveControl Is CommandButton Then
> > 'Screen.ActiveControl.Name_Click
> > End If
>
> Try this:
>
> If TypeOf Screen.ActiveControl Is CommandButton Then
> Screen.ActiveControl.Value = 1
> End If
>
>
>

Re: Interesting Lostfocus behavior by Eduardo

Eduardo
Tue Oct 14 07:21:46 CDT 2008

"SLink9" <SLink9@discussions.microsoft.com> escribió en el mensaje
news:43C3EF2D-84C6-4E1D-B1DF-892480BD40B2@microsoft.com...
> Eduardo,
>
> That worked beautifully for the command button. o you have a suggestion
> for
> processing a cListBar click? That is the other option for a click in this
> case and checking for a type of cListBar or cListBarItem does not trigger.

What is a cListBar?
May be this?:
http://www.vbaccelerator.com/home/VB/Code/Controls/ListBar/Outlook_ListBar/VB6_List_Bar_Full_Source.asp

If this is it, there you have the source code to add the properies or
methods that you need.

May be you prefer to do a "real" click in the ActiveControl, but that would
be using API calls.

You could get the mouse coordinates before asking the user anything, and
after you finished the validaton routine, do a click where the mouse was
before. It has to work with any control type.

The APIs are:
mouse_event: http://allapi.mentalis.org/apilist/mouse_event.shtml
GetCursorPos: http://allapi.mentalis.org/apilist/GetCursorPos.shtml

If you decide to test this possibility, i can write an example.



Re: Interesting Lostfocus behavior by SLink9

SLink9
Tue Oct 14 07:28:01 CDT 2008

The button that I am clicking on has TabStop = True. Setting the value of
activecontrol to 1 caused the code behind the button to execute. Now the
question is how to catch and process a click on a listbar item. The
lostfocus event seems to believe that the focus is still on the combobox
after the msgbox display and data verify.

"Bert van den Dongen" wrote:

> Couldn't it be that there is no other control
> with a TabStop = True available?
> It looks to me that the focus is unable to go
> to another control after clicking the combo.
> Bert.
>
>
> "SLink9" <SLink9@discussions.microsoft.com> schreef in bericht
> news:97B39414-A4E2-45C3-9879-9153106F682E@microsoft.com...
> > Since I can't seem to make VB6 behave as outlined in one of the replies to
> > this post I have placed code in the lostfocus of the combobox which
> > determines which item was clicked. It ten determines if a commandbutton
> > was
> > clicked. If a commandbutton was clicked I want to run the _click routine
> > for
> > it. I just thought of using with although I am unsure of how this will
> > work
> > in VB6. Here is the code.
> >
> > Dim curritm
> > curritm = Screen.ActiveControl.Name
> > If TypeOf Screen.ActiveControl Is CommandButton Then
> > 'Screen.ActiveControl.Name_Click
> > End If
> >
> > I am going to change the commented line to have
> >
> > with curitm
> > _click
> >
> > I don't believe that will work. Any suggestions for getting this
> > implemented? Better direction?
> >
>
>

Re: Interesting Lostfocus behavior by SLink9

SLink9
Tue Oct 14 07:33:01 CDT 2008

Thanks for the help. I believe that one has just been solved also. Yes,
that is what a cListBar is.

I had the code in LostFocus instead of Validate. Now that the verify code
is in validate and the activecontrol processing is in LostFocus the program
sees vbalListBar as the activecontrol. I can work with that now. Thanks.

"Eduardo" wrote:

> "SLink9" <SLink9@discussions.microsoft.com> escribió en el mensaje
> news:43C3EF2D-84C6-4E1D-B1DF-892480BD40B2@microsoft.com...
> > Eduardo,
> >
> > That worked beautifully for the command button. o you have a suggestion
> > for
> > processing a cListBar click? That is the other option for a click in this
> > case and checking for a type of cListBar or cListBarItem does not trigger.
>
> What is a cListBar?
> May be this?:
> http://www.vbaccelerator.com/home/VB/Code/Controls/ListBar/Outlook_ListBar/VB6_List_Bar_Full_Source.asp
>
> If this is it, there you have the source code to add the properies or
> methods that you need.
>
> May be you prefer to do a "real" click in the ActiveControl, but that would
> be using API calls.
>
> You could get the mouse coordinates before asking the user anything, and
> after you finished the validaton routine, do a click where the mouse was
> before. It has to work with any control type.
>
> The APIs are:
> mouse_event: http://allapi.mentalis.org/apilist/mouse_event.shtml
> GetCursorPos: http://allapi.mentalis.org/apilist/GetCursorPos.shtml
>
> If you decide to test this possibility, i can write an example.
>
>
>