I've been trying to understand and get this to work all day. I've been all over this forum and Google. I've found a lot of material and come up with some code and workarounds, but something is still not right.
I confess, I'm trying to set-up navigating with the tab key and shift+tab between a main form and two subforms. I've learned that control+tab will move out of the subform and onto the main form "forward" on the tab indexes and that control+shift+tab will move onto the main form "backward" according to the tab indexes.
I've also learned that for some reason Access often skips the first tab stop outside the subform and moves to the next one. So I've added almost invisible text boxes around the subforms to absorb this and let the tab rest on the desired control - the next one outside of the subform. It looks a bit funny to have the cursor stop on un-otherwise-noticeable-places-on-the-form. I haven't found an explanation for this skipping thing, though. ??
I'm trying to trap the shift+tab keystroke action in the combobox that is the only control on the first subform so I can send the user to the "previous" control on the main form. When I do it myself it works fine, but when I try to use some version of sendkeys the cursor just stays in the combo box.
I've been trying to come up with some keystroke arithmetic to set a value for a variable to determine what sendkeys action comes next. But I can't get the math to work.
I'm working within the KeyDown event of the only control on the subform, a combobox.
As I've tried to figure it out, I'm noticing that the "keycode" value from the KeyDown event is equal to 16 if I'm trying to shift+tab and is equal to 9 if I'm just hitting tab. Checking this out, looks like the shift key is "worth" 16 and the tab key is "worth" 9. So, KeyDown is recognizing only the first key hit, just the Shift. How can I get something that will catch shift+tab?
I also found in the Access Help File the following code:
From which I've learned that the acShiftMask is "worth" 1, acAltMask is "worth" 4, and acCtrlMask is "worth" 2.
I thought a Select Case approach might be a good idea. Here's what I have that doesn't work:
Another approach that isn't working is:
Could someone please help me understand this better? I seem to be stuck in a vortex here. Thanks!!!
I confess, I'm trying to set-up navigating with the tab key and shift+tab between a main form and two subforms. I've learned that control+tab will move out of the subform and onto the main form "forward" on the tab indexes and that control+shift+tab will move onto the main form "backward" according to the tab indexes.
I've also learned that for some reason Access often skips the first tab stop outside the subform and moves to the next one. So I've added almost invisible text boxes around the subforms to absorb this and let the tab rest on the desired control - the next one outside of the subform. It looks a bit funny to have the cursor stop on un-otherwise-noticeable-places-on-the-form. I haven't found an explanation for this skipping thing, though. ??
I'm trying to trap the shift+tab keystroke action in the combobox that is the only control on the first subform so I can send the user to the "previous" control on the main form. When I do it myself it works fine, but when I try to use some version of sendkeys the cursor just stays in the combo box.
I've been trying to come up with some keystroke arithmetic to set a value for a variable to determine what sendkeys action comes next. But I can't get the math to work.
I'm working within the KeyDown event of the only control on the subform, a combobox.
Code:
Private Sub cboMedicalCondition_KeyDown(KeyCode As Integer, Shift As Integer)
end sub
As I've tried to figure it out, I'm noticing that the "keycode" value from the KeyDown event is equal to 16 if I'm trying to shift+tab and is equal to 9 if I'm just hitting tab. Checking this out, looks like the shift key is "worth" 16 and the tab key is "worth" 9. So, KeyDown is recognizing only the first key hit, just the Shift. How can I get something that will catch shift+tab?
I also found in the Access Help File the following code:
Code:
Dim intShiftDown As Integer, intAltDown As Integer
Dim intCtrlDown As Integer
' Use bit masks to determine which key was pressed.
intShiftDown = (Shift And acShiftMask) > 0
intAltDown = (Shift And acAltMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0
' Display message telling user which key was pressed.
If intShiftDown Then MsgBox "You pressed the SHIFT key."
If intAltDown Then MsgBox "You pressed the ALT key."
If intCtrlDown Then MsgBox "You pressed the CTRL key."
From which I've learned that the acShiftMask is "worth" 1, acAltMask is "worth" 4, and acCtrlMask is "worth" 2.
I thought a Select Case approach might be a good idea. Here's what I have that doesn't work:
Code:
Dim lngValue As Integer
lngValue = KeyCode + Shift 'These are the variables in the KeyDown event
Select Case lngValue
Case 9 'tab key alone = 9
KeyCode = 0
SendKeys "^{tab}"
Case 10 'tab key = 9; shift key = 1
KeyCode = 0
SendKeys "^+{tab}"
Case Else
KeyCode = 0
SendKeys "^{tab}"
End Select
Another approach that isn't working is:
Code:
If KeyCode = vbKeyTab Then
KeyCode = 0
SendKeys "^{tab}"
End If
If KeyCode + Shift = vbKeyTab + vbKeyShift Then 'Here's a place where the math doesn't work
SendKeys "^+{tab}"
Me.Parent.txtTabMgt1.SetFocus 'This SetFocus approach isn't working either, when I try it alone
End If
Could someone please help me understand this better? I seem to be stuck in a vortex here. Thanks!!!