form keypress event in subform

boerbende

Ben
Local time
Today, 10:54
Joined
Feb 10, 2013
Messages
339
Dear readers,

I have a form which consists of 20 similar subforms.
The subform has only two fields.
When I want to go to the next subform, I use CTRL TAB
But I want to use only TAB.
I have tried a couple of things with the keypress event of that control, but cannot find a solution that works

What I would liike:
- when the user is pressing TAB in the last field of a subform, that the program reacts like CTRL TAB and goes to the next subform.

Many thanks

Ben de Boer
 
Always helpful if you post your attempt so we can fix it. You're in the right event, and if memory serves you want to test for 9.
 
Thank You. I know i have to test for vbkeytab =9, and i see that
Shift = 2 when pressing both Tab and Ctrl, but my question is:
when I test on key code=9, what do I have to return for both shift and key code.

Regards
Ben
 
I'm not sure I understand. Just checked some code, and I just test for KeyAscii = 9.
 
Thanks for thinking with me (or was it for me ;) ).

Background:
I have inherited this application and looking for improvements.
In my subform the CTRL TAB sends me to the next subform.
Problem is that I cannot explain this keycombination to 40 operators. They are used to Enter or TAB
So I was thinking to change the TAB control on the last field in the subform.
Hence the question

Underneath the code I was trying. But I could not find yet the values I have to enter for KeyCode and Shift.

Many regards,

Ben

Private Sub Text1_KeyDown(KeyCode As Integer, _ Shift As Integer)
If Keycode = vbKeyTab then
Keycode = ??
shift = ??
endif

End sub
 
I have been able to successful do what you want. I use the On Exit event of the last control on the form. In the On Exit I set the focus to a control on the parent form.

If the sub form is in continuous view it gets a little more complicated. You need to also see if you are on the last record before exiting the sub form.
 
I use the key press event as you first mentioned. If the value is 9 I set focus where I want it. I use it also on continuous subforms so the user can jump out early if they want.
 
I used to also trap keys. I found that using the On Exit event make it keyboard independent. That means both the Enter key and Tab keys will work withou the same code.

If you only want the behavior for a single key then you will need to trap the key.

At least for my apps the On Exit works great.
 
I use the key press event as you first mentioned. If the value is 9 I set focus where I want it. I use it also on continuous subforms so the user can jump out early if they want.

About continuous subforms:

Curious, do you have the form set to cycle the current record so Tab does not take then to a new record?

For speed, my data entry users like to tab to new record. I use the On Exit for forms that are only adding new records.
 
In these particular forms, users may or may not have to go through all the records. They are data entry forms where each record in a subform is a rate the driver may or may not have used during his shift, or something similar. When they've entered his last rate, they like to be able to jump out of the subform, rather than move through all of them until the last (there are 10 or so). They can use the enter key to move down the form, or the tab key to jump out. They guys whine about every extra keystroke, plus they prefer not to have to use the mouse.
 
In these particular forms, users may or may not have to go through all the records. They are data entry forms where each record in a subform is a rate the driver may or may not have used during his shift, or something similar. When they've entered his last rate, they like to be able to jump out of the subform, rather than move through all of them until the last (there are 10 or so). They can use the enter key to move down the form, or the tab key to jump out. They guys whine about every extra keystroke, plus they prefer not to have to use the mouse.

Ah... that makes sense. In your case you do have to tap the key if you want the enter key and tab to to have different functionality.

I totally get the saving keystrokes. I do everything I can to avoid having to using the mouse on data entry forms. The mouse really does slow down a person that can type fast.
 
So maybe a setfocus on the onexit event. But how do I do this?
It's not a continuous subform. I have 20 x the same subform linked in 1 main form. I know the names, but it requires some code to first find out in which subform I am. When this is known I can set a focus on the next form.

I can also use the tab index of the subforms in the main form. the first subform is tabindex 2, the second = 3 and so on. Is it possible to use this.

But what about my first question. CTRL TAB works to go from one subform to the next one.
It seemed so easy to replace a keycode TAB (=one key) in the last object in the subform with CTRL TAB (=two keys) by using the keypress event. Does somebody have experience with this?

Many thanks Regards,

Ben
 
So maybe a setfocus on the onexit event. But how do I do this?
It's not a continuous subform. I have 20 x the same subform linked in 1 main form. I know the names, but it requires some code to first find out in which subform I am. When this is known I can set a focus on the next form.

I can also use the tab index of the subforms in the main form. the first subform is tabindex 2, the second = 3 and so on. Is it possible to use this.

Ben,

To use the On Exit you will probably need to edit each subform manually. You will add code to the On exit event of the last control.

Are you wanting to try to make some generic code that can be called from every subform?


But what about my first question. CTRL TAB works to go from one subform to the next one.
It seemed so easy to replace a keycode TAB (=one key) in the last object in the subform with CTRL TAB (=two keys) by using the keypress event. Does somebody have experience with this?

The only way I know to do what you want is to use the dreaded SendKeys. If I dared to try it I would use this API: Replacement for Sendkeys
 
I am almost there thanks to your remarks.

I still think it is possible to use the keypress on the last field in the subform.

********
If KeyCode = vbKeyTab Then

tabIndexCounter = how do I retrieve the tabindex of the subform I am editing a field in? So the tabindex of the subform in the main form
Afterwards it is easy to jump to the next subform with
Forms![MainForm].Form.Controls(TabIndexCounter +1).SetFocus

Endif
********
Many regards,

Ben
 

Users who are viewing this thread

Back
Top Bottom