Tab Control Subform Events

S

scott

I have a tab control and a subform on the 3rd tab. With help from a MVP, I
was able to detect if a user clicked the 3rd tab, as code below shows, and
setfocus to the subform, move to new record. I need the subform to default
to a new record even if a user advances to a different record on main form.

Below code works fine on the tab control if a user clicks the "3rd tab".
However, if user advances to the next record while on the "3rd tab", the
subform looses focus and I don't know how to detect if a user goes to a new
record and is on the "3rd tab".

Any ideas?


Private Sub tab_DataForm_Change()
Dim strErrorMsg As String
Dim strTabCntrlSource As String
Dim strLinkMaster As String
Dim strLinkChild As String
Dim subfrm As Access.SubForm

Select Case Me.tab_DataSubForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing

Case "3rd"
Forms![myform]![myform_sub]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

End Sub
 
M

MacDermott

Moving to a different record on the main form will cause that form's
OnCurrent event to fire.
The value of the tabcontrol on the subform will not be affected, so you can
still test whether it's 3.
 
S

scott

i've got below code firing on the "On Current" event. Now it doesn't fire
when I select the "3rd" tab for a record. Then when I advance to a 2nd
record on main form after the 1st time, it sends me to a new record on the
main form, instead of staying on the 2nd or current record and setting focus
on the subform and going to a new record on the sub form.

Any ideas?

Dim subfrm As Access.SubForm

On Error GoTo ErrorHandler

Select Case Me.tab_DataForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing
Case "3rd"
Forms![mymainform]![mysubform]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

MacDermott said:
Moving to a different record on the main form will cause that form's
OnCurrent event to fire.
The value of the tabcontrol on the subform will not be affected, so you
can
still test whether it's 3.

scott said:
I have a tab control and a subform on the 3rd tab. With help from a MVP,
I
was able to detect if a user clicked the 3rd tab, as code below shows,
and
setfocus to the subform, move to new record. I need the subform to
default
to a new record even if a user advances to a different record on main form.

Below code works fine on the tab control if a user clicks the "3rd tab".
However, if user advances to the next record while on the "3rd tab", the
subform looses focus and I don't know how to detect if a user goes to a new
record and is on the "3rd tab".

Any ideas?


Private Sub tab_DataForm_Change()
Dim strErrorMsg As String
Dim strTabCntrlSource As String
Dim strLinkMaster As String
Dim strLinkChild As String
Dim subfrm As Access.SubForm

Select Case Me.tab_DataSubForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing

Case "3rd"
Forms![myform]![myform_sub]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

End Sub
 
M

MacDermott

I think setting focus to a control on the subform is sometimes best
accomplished in 2 steps:
Forms![mymainform]![mysubform].SetFocus
Forms![mymainform]![mysubform].form![myDateField].SetFocus

HTH

scott said:
i've got below code firing on the "On Current" event. Now it doesn't fire
when I select the "3rd" tab for a record. Then when I advance to a 2nd
record on main form after the 1st time, it sends me to a new record on the
main form, instead of staying on the 2nd or current record and setting focus
on the subform and going to a new record on the sub form.

Any ideas?

Dim subfrm As Access.SubForm

On Error GoTo ErrorHandler

Select Case Me.tab_DataForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing
Case "3rd"
Forms![mymainform]![mysubform]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

MacDermott said:
Moving to a different record on the main form will cause that form's
OnCurrent event to fire.
The value of the tabcontrol on the subform will not be affected, so you
can
still test whether it's 3.

scott said:
I have a tab control and a subform on the 3rd tab. With help from a MVP,
I
was able to detect if a user clicked the 3rd tab, as code below shows,
and
setfocus to the subform, move to new record. I need the subform to
default
to a new record even if a user advances to a different record on main form.

Below code works fine on the tab control if a user clicks the "3rd tab".
However, if user advances to the next record while on the "3rd tab", the
subform looses focus and I don't know how to detect if a user goes to a new
record and is on the "3rd tab".

Any ideas?


Private Sub tab_DataForm_Change()
Dim strErrorMsg As String
Dim strTabCntrlSource As String
Dim strLinkMaster As String
Dim strLinkChild As String
Dim subfrm As Access.SubForm

Select Case Me.tab_DataSubForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing

Case "3rd"
Forms![myform]![myform_sub]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

End Sub
 
S

scott

That does set focus as I was trying to the subform on the 3rd tab. I had to
create a public variable to hold the value of which tab is being used to
prevent the form from forcing user to the 3rd tab on easch record, but it
works great.

Thanks for the help and a lesson on tabs.

MacDermott said:
I think setting focus to a control on the subform is sometimes best
accomplished in 2 steps:
Forms![mymainform]![mysubform].SetFocus
Forms![mymainform]![mysubform].form![myDateField].SetFocus

HTH

scott said:
i've got below code firing on the "On Current" event. Now it doesn't fire
when I select the "3rd" tab for a record. Then when I advance to a 2nd
record on main form after the 1st time, it sends me to a new record on
the
main form, instead of staying on the 2nd or current record and setting focus
on the subform and going to a new record on the sub form.

Any ideas?

Dim subfrm As Access.SubForm

On Error GoTo ErrorHandler

Select Case Me.tab_DataForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing
Case "3rd"
Forms![mymainform]![mysubform]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

MacDermott said:
Moving to a different record on the main form will cause that form's
OnCurrent event to fire.
The value of the tabcontrol on the subform will not be affected, so you
can
still test whether it's 3.

I have a tab control and a subform on the 3rd tab. With help from a MVP,
I
was able to detect if a user clicked the 3rd tab, as code below shows,
and
setfocus to the subform, move to new record. I need the subform to
default
to a new record even if a user advances to a different record on main
form.

Below code works fine on the tab control if a user clicks the "3rd tab".
However, if user advances to the next record while on the "3rd tab", the
subform looses focus and I don't know how to detect if a user goes to
a
new
record and is on the "3rd tab".

Any ideas?


Private Sub tab_DataForm_Change()
Dim strErrorMsg As String
Dim strTabCntrlSource As String
Dim strLinkMaster As String
Dim strLinkChild As String
Dim subfrm As Access.SubForm

Select Case Me.tab_DataSubForm.Pages(Me.tab_DataForm).Name

Case "1st"
' nothing

Case "3rd"
Forms![myform]![myform_sub]![myDateField].SetFocus
DoCmd.GoToRecord , , acNewRec
Case Else
Exit Sub

End Select

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top