Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab between form and subforms to sub forms on a tab control?

Status
Not open for further replies.

misscrf

Technical User
Jun 7, 2004
1,344
US
I have a main entry for and a tab control with 5 pages. Each page has an independant sub form which each tie 1 to many to the main form. I want to allow users to tab through from the first field on the main through each sub form and back to the main form. I have done this in the past by using an invisible text box that has code to move the focus to the next form | first field. This is how it works.

I have an unbound text box on the main form and each sub form called txtExit. It is invisible and is also the last field in the tab order on each form. In the Enter property of the control I have the following code:

Code:
Private Sub txtExit_Enter()
Forms![frmMain]![frmSubForm1].SetFocus
Forms![frmMain]![frmSubForm1].Form![SubForm1FirstField].SetFocus
End Sub

This works going form the main form to the first sub form and it works going from the first sub form on the first page of the tab control to the second sub form on the second page of the tab control. Once I tab through the second sub form's controls, it just keeps tabbing through that form and doesn't go to the next form. I have checked the code to the names of the controls on the 3rd form and copy pasted the names. I have checked that the txtExit on the 2nd form has a tab stop yes, etc.

What am I missing? Is there a better way to do this, please?

Any help is greatly appreciated.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
This works for me using your idea of a hidden text box.
1) on the main form

Public Sub moveFocus(strFrm As String, strControl As String)
Me.Controls(strFrm).SetFocus
Me.Controls(strFrm).Form.Controls(strControl).SetFocus
End Sub

2) on any subform
Private Sub Text34_Enter()
Call Me.Parent.moveFocus("subfrmTwo", "EmployeeID")
End Sub

where strFrm is the subform you want to move to, strControl is the name of the control to move to.
 
Thank you for replying and trying out my setup.

What about if you have a tab control and on one page you have a subform and another subform on a second page (both independant but tied to main form with links). Then using that field on the first subform, have the tab focus to go the 3rd form (second subform) from first from 1 tab control page to the next.

I ended up having to make my txtExit controls visible, but just made them blend into the back ground. Because the code is in the Enter property, users don't know they just went into another field. It happens too fast. I don't know if this is a bad idea, having a visible, but not noticable unbound field on a sub form that has code to move a user to the next form...
Feels messy but looks cool lol.



misscrf

It is never too late to become what you could have been ~ George Eliot
 
That is what the code does.

Assume I have subFrmOne, subFrmTwo, and SubFrmThree. I want to go from SubFrmOne control 1A to subFrmTwo and control 2A. Then from subfrmTwo to subFrmThree control 3A. Then subfrmThree back to subFrmOne control 1A

On my subforms
subfrmOne
Private Sub hiddenTextBox_Enter()
Call Me.Parent.moveFocus("subfrmTwo", "2A")
End Sub

subFrmTwo
Private Sub hiddenTextBox_Enter()
Call Me.Parent.moveFocus("subfrmThree", "3A")
End Sub

subFrmThree
Private Sub hiddenTextBox_Enter()
Call Me.Parent.moveFocus("subfrmOne", "1A")
End Sub
 
Thank you. I think since it doesn't look broken, I will leave it for now. I will post back if I find any problems or holes in this set up.



misscrf

It is never too late to become what you could have been ~ George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top