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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Tab From Subform to Main Form

Status
Not open for further replies.

tammy23

Technical User
Aug 3, 2010
17
US
I need to be able to Tab from the Last Record on a subform back to the Header on my main form...I tried using SetFocus OnExit but then I can't scroll through every Record on the subform, only the first one. I also tried using an event procedure OnExit from the subform but the Tab just loops through the last record at that point. Any ideas....don't really know what code to post to get this started. Thanks, T
 
Check to see if you are at the last record as well

Private Sub someControl_LostFocus()
Dim cnt As Integer
cnt = Me.RecordsetClone.RecordCount
If cnt = Me.Recordset.AbsolutePosition + 1 Then
Me.Parent.someParentControl.SetFocus
End If
End Sub

if you are adding records to the subform you may want to replace with
Me.Recordset.AbsolutePosition + 1
with
e.Recordset.AbsolutePosition
 
Works fine for me.

Put this Msgbox in the code and tell me the values you get after tabbing out of last control

Private Sub someControl_LostFocus()
Dim cnt As Integer
cnt = Me.RecordsetClone.RecordCount
msgbox "Cnt " & cnt & " Ab Pos " & me.recordset.absolutePosition
If cnt = Me.Recordset.AbsolutePosition + 1 Then
Me.Parent.someParentControl.SetFocus
End If
End Sub
 
Thanks!...I got it but I changed the code a little to this:

Private Sub Text20_LostFocus()
Dim cnt As Integer
cnt = Me.RecordsetClone.RecordCount
MsgBox "Cnt " & cnt & " Ab Pos " & Me.Recordset.AbsolutePosition
If cnt = Me.Recordset.AbsolutePosition + 1 Then
Forms!WellLogSearch.Form![Combo10].SetFocus
End If
End Sub


This statement was giving me an error:

Me.Parent.someParentControl.SetFocus

-T
 
That was meant to be an example of a control name
Me.Parent.someParentControl.SetFocus

me.Parent.combo10.setfocus
 
Thanks, sorry... I thought I was supposed to replace "Parent" with the Form name...your code works fine...thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top