Many ways to skin a cat in MS Access. This is just one. In the On Lost Focus event procedure of the last field of the subform, set the focus to the first field on the main form like so...
You could put code in the KeyPress event for the textbox in question to send the focus back for a particular key, like the enter key. It would look something like...
If KeyAscii = vbKeyReturn Then
Forms![MainFormName]![FirstFieldName].SetFocus
End If
What i happened to discover once is Ctrl-Tab.
It only helps to get out of the subform, there's no inverse function with shift or so (but you didn't ask for that in the first place).
This keystroke that seems to work most of the time, but I guess that when the focus within the the subform is on a tabstrip, the keystroke will affect that tabstrip.
Actually it seems like it takes you to the next control in the tab-order on the main form, and shift-ing it takes you to the previous.
This is exactly what I need to do, however I put in the same code in my last field on my submform just as indicated in the thread... it's not working for me.
The focus still goes to the first field in the subform instead of jumping to the main form.
Is the field that you are sending the focus to a field that allows the focus? Be sure the tab stop property is set to Yes and the Enabled property is set to Yes.
If it isn't resolved yet, you could try the keydown event in stead.
When a keystroke causes focus to move to another control (enter/tab), the keydown event is recieved by the first control, whilst the keypressed event is received by the next control (first control of the subform).
Sample code:
[tt]if keycode = vbkeyreturn then
Me.Parent!FirstControlName.SetFocus
keycode=0 ' cancelling the enter key...
end if[/tt]
I am finding that both the keydown and keypress events "sort of" get me to where I want to go but not consistently. My set up is that I have a main form with 2 subforms. I want to be able to tab/enter across 2 text boxes on the main form then straight into the first 2 text boxes on the first subform and then straight into the first 2 text boxes on the 3rd subform. In essence, I am visually tabbing/entering across a row of 6 textboxes on my form (but the user is unaware that the form is made up of a main and 2 subforms). Here is the code I am using:
Private Sub BG2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Or vbKeyReturn Then
Forms!frmcsauditflex![subformFLEXBillingGroups]!.SetFocus
End If
End Sub
What I am finding is that often, once I hit tab or enter from the 2nd text box, it takes me to the second text box on the subform. Also, if I enter the number 1 in the text box, it jumps around everywhere....
Any suggestions?
Dawn Coleman, Business Analyst
UnumProvident Corporation
PLEASE RECYCLE AND ENCOURAGE YOUR OFFICE/COWORKERS TO DO SO AS WELL.
Think perhaps MorningSun's question here (the jumping to the second control of the sub) is answered in my previous reply, one need to cancel the keystroke. Difference between the keydown and keypressed is that keypressed uses KeyAscii, see below for this version.
In addition, to make the iftest work, one need to do the comparison on both conditions:
[tt]If KeyAscii = vbKeyTab Or KeyAscii = vbKeyReturn Then
KeyAscii = 0 ' cancel the keystroke
...[/tt]
The behaviour after pressing 1, I don't understand. There might be other event's firing?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.