Solved How to Set Shift+Tab to Jump Two Controls Instead of One (1 Viewer)

Pac-Man

Active member
Local time
Today, 23:53
Joined
Apr 14, 2020
Messages
408
Hello,

I have a combo (cboSource) and a textbox (txtTarget) in my form and when cursor enters into txtTarget , txtTarget_Enter event is trapped and have code to move the focus to cboSource. When user presses shift+tab, it cannot go back so want that if user presses shift+tab in that combo, focus should jump to two controls back instead of one. I know I have to trap cboSource OnKeyDown even but don't know to how go two controls back. Can anyone help me sort it out. I hope my query is clear and if not I will explain further.

Best Regards,
Abdullah
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:53
Joined
Sep 21, 2011
Messages
14,046
Move the controls to the order you require them.
It would be confusing as hell to the user, if the cursor was jumping over controls all over the place. :(
 

Pac-Man

Active member
Local time
Today, 23:53
Joined
Apr 14, 2020
Messages
408
Thanks for replying. While filling the form, user navigate among the controls using Tab key on keyboard. Tab order is correctly in the form. The aforementioned combo and textbox are overlapped each other and combo is set to invisible. When txtTarget got focus using either by Tab key or by mouse, cboSource is set to visible and also got focus by code in txtTarget_Enter event. On after update even of the cbo, code exist which put value of cboSource into txtTarget and again set cbosource invisible. This is my requirement. I simulated excel like autocomplete feature for txtTarget.

Sometime user have to navigate to previouse control using shift+tab key combination and then in above case he cannot move to previous control as each time he enters into txtTarget, code in OnEnter even of txtTarget is run and move the cursor to cboSource. So I have to put to code in OnKeyDown even of combo so that cursor may be moved two control back if shift+tab is pressed in the cboSource. So how can I move two controls back for this cboSource.
 

June7

AWF VIP
Local time
Today, 10:53
Joined
Mar 9, 2014
Messages
5,423
I did a test. When control is not visible, tab and shift+tab skip it. Unless in datasheet view - Visible set as No is ignored. However, it is skipped when Enabled is set No.
 
Last edited:

Pac-Man

Active member
Local time
Today, 23:53
Joined
Apr 14, 2020
Messages
408
I did a test. When control is not visible, tab and shift+tab skip it. Unless in datasheet view - Visible set as No is ignored. However, it is skipped when Enabled is set No.
Thanks for reply but when my textbox get focus, combo is set to visible so focus moves to combo. When user presses shift tab again, focus moves to textbox and again OnEnter code of txtbox is run and focus moves to cbo again and loop continues that is why I wish to move two controls back when user presses shift + tab in combo so that instead of textbox, control before textbox gets the focus.
When txtTarget got focus using either by Tab key or by mouse, cboSource is set to visible and also got focus by code in txtTarget_Enter event.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:53
Joined
May 7, 2009
Messages
19,169
you can Directly Setfocus on the control you want to go.
 

Attachments

  • backTab.accdb
    400 KB · Views: 316

Pac-Man

Active member
Local time
Today, 23:53
Joined
Apr 14, 2020
Messages
408
you can Directly Setfocus on the control you want to go.
Thanks a lot @arnelgp for the demo. But in this case the control has to be hard coded. I want this function relative to the combo as I am writing class module and this will be used in multiple forms multiple time.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:53
Joined
Sep 21, 2011
Messages
14,046
It is like pulling teeth. :(
Why not give ALL the details up front, instead of bit by bit. :unsure:
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:53
Joined
May 7, 2009
Messages
19,169
I want this function relative to the combo as I am writing class module and this will be used in multiple forms multiple time.
what do you mean, always have textbox that setfocus to combo?
 

Pac-Man

Active member
Local time
Today, 23:53
Joined
Apr 14, 2020
Messages
408
what do you mean, always have textbox that setfocus to combo?
I mean whenever txtTarget gets focus, following code in the OnEnter event moves the focus to cboSource.
Code:
If IsNull(txtTarget) Then
    cboSource.Visible = True
    cboSource.SetFocus
End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:53
Joined
May 7, 2009
Messages
19,169
here is another version, not Hardcoded.
 

Attachments

  • backTab.accdb
    552 KB · Views: 381

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:53
Joined
May 7, 2009
Messages
19,169
so the combo is hidden first?
i made a Class, check if you can get this work.
 

Attachments

  • backTab.accdb
    512 KB · Views: 384

Pac-Man

Active member
Local time
Today, 23:53
Joined
Apr 14, 2020
Messages
408
so the combo is hidden first?
i made a Class, check if you can get this work.
Thanks a lot. I had written almost similar to this class. I was having trouble re-hiding the combo after exiting the combo but got idea from your class to put the code to hide cbo in OnEnter or OnGotFocus event of textbox. Thanks again.
 

Users who are viewing this thread

Top Bottom