473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Returning Focus to Main Form

OK, this is a stupid thing, but I can't seem to get this to work. I have a
form with a subform (in continuous form view). A combo box on the main form
has code in the AfterUpdate event which adds a record to the subform (based
on the value of the combo box) and requeries the subform control. I want the
focus to return to the combo box on the main form when it's done, but I
can't get it to do so if the user enters a value and presses Enter (which
tabs to the next control, which is the subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil
Nov 13 '05 #1
17 3805
I think you're setting yourself up for some failure here. How will your code
let the user leave the textbox at all if you intercept a focus move and
don't let the focus go elsewhere? If you put code on the textbox to stop the
focus move, that is what will happen.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but I
would think that your users will get very tired of having to remember that
the Enter key won't work to move along for just that one control on the
form.

I suggest that you think of a different approach for what you want to
achieve.

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I have a
form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the subform
(based on the value of the combo box) and requeries the subform control. I
want the focus to return to the combo box on the main form when it's done,
but I can't get it to do so if the user enters a value and presses Enter
(which tabs to the next control, which is the subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil

Nov 13 '05 #2
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?
If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that I
want to move the focus back to the combo box. Thus, if the user enters a
value and hits Enter, the result is that the focus is back in the combo box.
If the user is just tabbing through the controls, pressing Enter or Tab,
they can leave it fine. No code is activated.
If you put code on the textbox to stop the focus move, that is what will
happen.
Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.
Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but I
would think that your users will get very tired of having to remember that
the Enter key won't work to move along for just that one control on the
form.
Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.
Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the subform
(based on the value of the combo box) and requeries the subform control.
I want the focus to return to the combo box on the main form when it's
done, but I can't get it to do so if the user enters a value and presses
Enter (which tabs to the next control, which is the subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil


Nov 13 '05 #3
OK. Put a hidden textbox on the form -- name it txtNoGo. Set its
DefaultValue to 0.

In your textbox's AfterUpdate event, use this code:

Private Sub TextBoxName_AfterUpdate()
Me.txtNoGo = 1
End Sub
In the textbox's Exit event, use this code:

Private Sub TextBoxName_Exit(Cancel As Integer)
If Me.txtNoGo = 1 Then
Me.txtNoGo = 0
Cancel = True
End If

This will use a hidden textbox as a flag to know that you've updated the
textbox's value and that the focus should not move.

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:kd*****************@newsread3.news.pas.earthl ink.net...
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?


If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that I
want to move the focus back to the combo box. Thus, if the user enters a
value and hits Enter, the result is that the focus is back in the combo
box. If the user is just tabbing through the controls, pressing Enter or
Tab, they can leave it fine. No code is activated.
If you put code on the textbox to stop the focus move, that is what will
happen.


Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.


Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but
I would think that your users will get very tired of having to remember
that the Enter key won't work to move along for just that one control on
the form.


Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.


Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the
subform (based on the value of the combo box) and requeries the subform
control. I want the focus to return to the combo box on the main form
when it's done, but I can't get it to do so if the user enters a value
and presses Enter (which tabs to the next control, which is the
subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil



Nov 13 '05 #4
FYI... I note that I mistakenly referred to your control as a textbox in my
replies. Code will work for combo box as well.
--

Ken Snell
<MS ACCESS MVP>

"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:kd*****************@newsread3.news.pas.earthl ink.net...
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?


If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that I
want to move the focus back to the combo box. Thus, if the user enters a
value and hits Enter, the result is that the focus is back in the combo
box. If the user is just tabbing through the controls, pressing Enter or
Tab, they can leave it fine. No code is activated.
If you put code on the textbox to stop the focus move, that is what will
happen.


Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.


Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but
I would think that your users will get very tired of having to remember
that the Enter key won't work to move along for just that one control on
the form.


Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.


Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the
subform (based on the value of the combo box) and requeries the subform
control. I want the focus to return to the combo box on the main form
when it's done, but I can't get it to do so if the user enters a value
and presses Enter (which tabs to the next control, which is the
subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil



Nov 13 '05 #5
Understood.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
FYI... I note that I mistakenly referred to your control as a textbox in
my replies. Code will work for combo box as well.
--

Ken Snell
<MS ACCESS MVP>

"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:kd*****************@newsread3.news.pas.earthl ink.net...
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?


If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that
I want to move the focus back to the combo box. Thus, if the user enters
a value and hits Enter, the result is that the focus is back in the combo
box. If the user is just tabbing through the controls, pressing Enter or
Tab, they can leave it fine. No code is activated.
If you put code on the textbox to stop the focus move, that is what
will happen.


Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.


Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user
move the focus if he/she presses Tab key or clicks into another
control), but I would think that your users will get very tired of
having to remember that the Enter key won't work to move along for just
that one control on the form.


Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.


Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I
have a form with a subform (in continuous form view). A combo box on
the main form has code in the AfterUpdate event which adds a record to
the subform (based on the value of the combo box) and requeries the
subform control. I want the focus to return to the combo box on the
main form when it's done, but I can't get it to do so if the user
enters a value and presses Enter (which tabs to the next control, which
is the subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil



Nov 13 '05 #6
Interesting approach. You'd think it would be possible to do it directly in
code. I seem to recall in the past that I was able to do that, by just using
SetFocus. I don't know if I'm remembering wrongly, or if something's
changed.

In any case, your solution works fine in the case where the user presses
Enter after entering a value. But it has problems in other scenarios:

* If the user uses the mouse to select a value from the combo box and then
presses Enter to leave the combo box , the focus stays in the combo box.

* Similarly, if the user uses the mouse to select a value and then clicks a
command button or tries to go to a new record, they are still stuck there
for at least one time.

Perhaps something in the KeyPress event, instead of Exit, would work? (Still
seems there should be a more direct approach....)

Thanks,

Neil

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
OK. Put a hidden textbox on the form -- name it txtNoGo. Set its
DefaultValue to 0.

In your textbox's AfterUpdate event, use this code:

Private Sub TextBoxName_AfterUpdate()
Me.txtNoGo = 1
End Sub
In the textbox's Exit event, use this code:

Private Sub TextBoxName_Exit(Cancel As Integer)
If Me.txtNoGo = 1 Then
Me.txtNoGo = 0
Cancel = True
End If

This will use a hidden textbox as a flag to know that you've updated the
textbox's value and that the focus should not move.

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:kd*****************@newsread3.news.pas.earthl ink.net...
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?


If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that
I want to move the focus back to the combo box. Thus, if the user enters
a value and hits Enter, the result is that the focus is back in the combo
box. If the user is just tabbing through the controls, pressing Enter or
Tab, they can leave it fine. No code is activated.
If you put code on the textbox to stop the focus move, that is what
will happen.


Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.


Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user
move the focus if he/she presses Tab key or clicks into another
control), but I would think that your users will get very tired of
having to remember that the Enter key won't work to move along for just
that one control on the form.


Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.


Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I
have a form with a subform (in continuous form view). A combo box on
the main form has code in the AfterUpdate event which adds a record to
the subform (based on the value of the combo box) and requeries the
subform control. I want the focus to return to the combo box on the
main form when it's done, but I can't get it to do so if the user
enters a value and presses Enter (which tabs to the next control, which
is the subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?

Thanks,

Neil



Nov 13 '05 #7
Neil Ginsberg wrote:
Interesting approach. You'd think it would be possible to do it directly in
code.


The Windows API SetFocus is sometimes a bit more responsive than the
Access SetFocus.

We may be able to use it as follows (mostly air ... code)

Private Declare Function SetFocusAPI _
Lib "user32" _
Alias "SetFocus" _
(ByVal hwnd As Long) _
As Long

Private Sub Label10_Click()
SetFocusAPI Form_MDACandESO.hwnd
End Sub

where MDACandESO is the name of the form to which focus is transferred.
We must use the Alias, of course, to avoid confusion with the Access
function.

In a not so thorough test of two forms this moves the focus to the form
called MDACandESO. This form must have a module for the nomenclature
Form_MDACandESO to work. I'm guessing one could use Forms("MDACandESO")
if it doesn't have a module, but I haven't tried that.

Of course, one might want to write some error handling code if one could
not be sure that Form_MDACandESO is open, or test its state with SysCmd.

Lyle
Nov 13 '05 #8
You can only cancel the movement of the focus by cancelling the Exit or
BeforeUpdate event. You can use the GotFocus event of a subsequent control
to move the focus to another control -- perhaps that is what you're thinking
of.

The scenarios that you mention are along the lines of what I'd posted
initially. Until you can identify what is a change that should not let the
focus move and what is not a change that should not let the focus move, it's
difficult to devise a 'perfect fit' for your scenario. As I'd mentioned
previously, you could try trapping for the Enter key being pressed and use
that to decide if the flag should be set or not, along with the AfterUpdate
changes.

You'll need to figure out the exact scenarios that should move focus and/or
the ones that shouldn't, and then develop the setup to handle the form's
actions the way you wish.
--

Ken Snell
<MS ACCESS MVP>

"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:15*****************@newsread1.news.pas.earthl ink.net...
Interesting approach. You'd think it would be possible to do it directly
in code. I seem to recall in the past that I was able to do that, by just
using SetFocus. I don't know if I'm remembering wrongly, or if something's
changed.

In any case, your solution works fine in the case where the user presses
Enter after entering a value. But it has problems in other scenarios:

* If the user uses the mouse to select a value from the combo box and then
presses Enter to leave the combo box , the focus stays in the combo box.

* Similarly, if the user uses the mouse to select a value and then clicks
a command button or tries to go to a new record, they are still stuck
there for at least one time.

Perhaps something in the KeyPress event, instead of Exit, would work?
(Still seems there should be a more direct approach....)

Thanks,

Neil

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
OK. Put a hidden textbox on the form -- name it txtNoGo. Set its
DefaultValue to 0.

In your textbox's AfterUpdate event, use this code:

Private Sub TextBoxName_AfterUpdate()
Me.txtNoGo = 1
End Sub
In the textbox's Exit event, use this code:

Private Sub TextBoxName_Exit(Cancel As Integer)
If Me.txtNoGo = 1 Then
Me.txtNoGo = 0
Cancel = True
End If

This will use a hidden textbox as a flag to know that you've updated the
textbox's value and that the focus should not move.

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:kd*****************@newsread3.news.pas.earthl ink.net...
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?

If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that
I want to move the focus back to the combo box. Thus, if the user enters
a value and hits Enter, the result is that the focus is back in the
combo box. If the user is just tabbing through the controls, pressing
Enter or Tab, they can leave it fine. No code is activated.

If you put code on the textbox to stop the focus move, that is what
will happen.

Again, just in AfterUpdate.
You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.

Not what I want.
Even if you trap to determine if the Enter key was pressed, and stop
the focus move only if that key is pressed (in other words, let the
user move the focus if he/she presses Tab key or clicks into another
control), but I would think that your users will get very tired of
having to remember that the Enter key won't work to move along for just
that one control on the form.

Again, don't want that. Just AfterUpdate.
I suggest that you think of a different approach for what you want to
achieve.

Hopefully my above notes have clarified what I'm trying to do here.

Neil
--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...
> OK, this is a stupid thing, but I can't seem to get this to work. I
> have a form with a subform (in continuous form view). A combo box on
> the main form has code in the AfterUpdate event which adds a record to
> the subform (based on the value of the combo box) and requeries the
> subform control. I want the focus to return to the combo box on the
> main form when it's done, but I can't get it to do so if the user
> enters a value and presses Enter (which tabs to the next control,
> which is the subform). I've tried:
>
> Me.SetFocus
> Me.MyCombo.SetFocus
>
> which doesn't seem to work. Any ideas?
>
> Thanks,
>
> Neil
>



Nov 13 '05 #9
Thanks for the tip. I added the code you gave to the subform, and created a
Label10 label, but there was no effect. Perhaps because the subform is part
of the main form, by setting focus to the main form we're not changing
anything?

In any case, since you said you got it to work, I'm wondering what your
setup was. Was one form a subform of the other?

Thanks,

Neil
"Lyle Fairfield" <ly******@yahoo.ca> wrote in message
news:uR******************@read1.cgocable.net...
Neil Ginsberg wrote:
Interesting approach. You'd think it would be possible to do it directly
in code.


The Windows API SetFocus is sometimes a bit more responsive than the
Access SetFocus.

We may be able to use it as follows (mostly air ... code)

Private Declare Function SetFocusAPI _
Lib "user32" _
Alias "SetFocus" _
(ByVal hwnd As Long) _
As Long

Private Sub Label10_Click()
SetFocusAPI Form_MDACandESO.hwnd
End Sub

where MDACandESO is the name of the form to which focus is transferred. We
must use the Alias, of course, to avoid confusion with the Access
function.

In a not so thorough test of two forms this moves the focus to the form
called MDACandESO. This form must have a module for the nomenclature
Form_MDACandESO to work. I'm guessing one could use Forms("MDACandESO") if
it doesn't have a module, but I haven't tried that.

Of course, one might want to write some error handling code if one could
not be sure that Form_MDACandESO is open, or test its state with SysCmd.

Lyle

Nov 13 '05 #10
rkc
Neil Ginsberg wrote:
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?

If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that I
want to move the focus back to the combo box. Thus, if the user enters a
value and hits Enter, the result is that the focus is back in the combo box.
If the user is just tabbing through the controls, pressing Enter or Tab,
they can leave it fine. No code is activated.

If you put code on the textbox to stop the focus move, that is what will
happen.

Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.

Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but I
would think that your users will get very tired of having to remember that
the Enter key won't work to move along for just that one control on the
form.

Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.

Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.eart hlink.net...
OK, this is a stupid thing, but I can't seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the subform
(based on the value of the combo box) and requeries the subform control.
I want the focus to return to the combo box on the main form when it's
done, but I can't get it to do so if the user enters a value and presses
Enter (which tabs to the next control, which is the subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?


<main form code>
Private m_ReturnFocus As Boolean

Private Sub YourSubForm_Enter()
If m_ReturnFocus Then
m_ReturnFocus = False
Me.MyCombo.SetFocus
End If
End Sub

Private Sub MyCombo_AfterUpdate()
m_ReturnFocus = True
End Sub
</main form code>

Nov 13 '05 #11
Thanks for the note. Problem here is that it does it for all AfterUpdates,
including those done with the mouse. Thus, if the user selects an item with
the mouse and then clicks in the subform, it wouldn't go. Need to be able to
keep it there just with Enter. If they select with the mouse, they should
then be able to click elsewhere.

Neil
"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:ob****************@twister.nyroc.rr.com...
Neil Ginsberg wrote:
See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think you're setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don't let the focus go elsewhere?

If you mean that the user will never be able to leave the combo box with
what I'm doing, that's not true. It's only in the AfterUpdate event that
I want to move the focus back to the combo box. Thus, if the user enters
a value and hits Enter, the result is that the focus is back in the combo
box. If the user is just tabbing through the controls, pressing Enter or
Tab, they can leave it fine. No code is activated.

If you put code on the textbox to stop the focus move, that is what will
happen.

Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.

Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but
I would think that your users will get very tired of having to remember
that the Enter key won't work to move along for just that one control on
the form.

Again, don't want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.

Hopefully my above notes have clarified what I'm trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.ear thlink.net...

OK, this is a stupid thing, but I can't seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the
subform (based on the value of the combo box) and requeries the subform
control. I want the focus to return to the combo box on the main form
when it's done, but I can't get it to do so if the user enters a value
and presses Enter (which tabs to the next control, which is the
subform). I've tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn't seem to work. Any ideas?


<main form code>
Private m_ReturnFocus As Boolean

Private Sub YourSubForm_Enter()
If m_ReturnFocus Then
m_ReturnFocus = False
Me.MyCombo.SetFocus
End If
End Sub

Private Sub MyCombo_AfterUpdate()
m_ReturnFocus = True
End Sub
</main form code>

Nov 13 '05 #12
rkc
Neil Ginsberg wrote:
Thanks for the note. Problem here is that it does it for all AfterUpdates,
including those done with the mouse. Thus, if the user selects an item with
the mouse and then clicks in the subform, it wouldn't go. Need to be able to
keep it there just with Enter. If they select with the mouse, they should
then be able to click elsewhere.


Your requirements seem to change with every reply.
Nov 13 '05 #13
You mean noting that the solution to the problem causes problems in other
areas is a "change in requirement"? OK, then.

"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:hc*****************@twister.nyroc.rr.com...
Neil Ginsberg wrote:
Thanks for the note. Problem here is that it does it for all
AfterUpdates, including those done with the mouse. Thus, if the user
selects an item with the mouse and then clicks in the subform, it
wouldn't go. Need to be able to keep it there just with Enter. If they
select with the mouse, they should then be able to click elsewhere.


Your requirements seem to change with every reply.

Nov 13 '05 #14
rkc
Neil Ginsberg wrote:
You mean noting that the solution to the problem causes problems in other
areas is a "change in requirement"? OK, then.


I mean to me it's not clear what you are trying to achieve.
I you feel it should be, O.K. then.
Nov 13 '05 #15
rkc
O.K. Now I'm thinking all you want to be able to do is to select or
enter a value in the combobox using the Enter key without tabing to the
next control, but tab to the next control if that's not what was done.

How about this...

<Main Form>
Private m_ReturnFocus As Boolean
Private m_EnterKey As Boolean

Private Sub MyCombo_AfterUpdate()
If m_EnterKey Then
m_ReturnFocus = True
End If
End Sub

Private Sub MyCombo_KeyDown(KeyCode As Integer, Shift As Integer)
m_EnterKey = False

If KeyCode = 13 Then
m_EnterKey = True
End If

End Sub

Private Sub TheSubForm_Enter()
If m_ReturnFocus Then
Me.MyCombo.SetFocus
End If
m_ReturnFocus = False
m_EnterKey = False
End Sub
</Main Form>
Nov 13 '05 #16
OK, you're probably right in that sometimes we're not clear in what we
explain, leaving out things that are obvious. In this case, I thought it was
obvious that the use of the mouse should not be affected by the solution,
but I should have stated that.

N

"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:rQ****************@twister.nyroc.rr.com...
Neil Ginsberg wrote:
You mean noting that the solution to the problem causes problems in other
areas is a "change in requirement"? OK, then.


I mean to me it's not clear what you are trying to achieve.
I you feel it should be, O.K. then.

Nov 13 '05 #17

O.K. Now I'm thinking all you want to be able to do is to select or
enter a value in the combobox using the Enter key without tabing to the
next control, but tab to the next control if that's not what was done.
Right, exactly! :-) And still be able to select with the mouse without the
focus being "stuck" there due to restricting it for the Enter key.

How about this...
Looks like that would work. Thanks.

Neil

<Main Form>
Private m_ReturnFocus As Boolean
Private m_EnterKey As Boolean

Private Sub MyCombo_AfterUpdate()
If m_EnterKey Then
m_ReturnFocus = True
End If
End Sub

Private Sub MyCombo_KeyDown(KeyCode As Integer, Shift As Integer)
m_EnterKey = False

If KeyCode = 13 Then
m_EnterKey = True
End If

End Sub

Private Sub TheSubForm_Enter()
If m_ReturnFocus Then
Me.MyCombo.SetFocus
End If
m_ReturnFocus = False
m_EnterKey = False
End Sub
</Main Form>

Nov 13 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Mark | last post by:
Hi, At the top of my php file I have got :- <body onblur="self.focus();"> so when I click off onto another window, my window comes back up in front which is perfect. The problem however, is...
5
by: Petec | last post by:
Is there a way to prevent a form from getting focus? Thanks! - Pete
1
by: cider123 | last post by:
I've tried working with the SelectedIndices and Items.Selected attributes to get the problem to go away, but not having any luck. Questions I have are: 1) How do you move (using code) the...
2
by: Sid Price | last post by:
Is there a way of stopping a form getting focus in VB.NET. The scenario I have is a main form and a form used for display only. There are no user controls on the display form and it does not ever...
3
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
3
by: Johnny Jörgensen | last post by:
I've a form that opens a tool window. The problem is that when the tool window is opened, the main form itself passes focus to the toolwindow. What I want and need is a toolwindow that works like...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
5
by: oscWork | last post by:
Does anyone know of any way to switch focus between a main form and a child form without the usual flickering you get while changing focus between windows? This works fine if the main form is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.