unable to set focus on subform

J

Jeri

I hope someone has a suggestion here. I've struggled with this issue for an
embarrassing amount of time, and can't find any threads that help. I have
several subforms on several different tabs, with "on update" code that
recalculates fields on a main form. All that code runs fine, but I can't
persuade the focus to return to the subform. Here's the code that begins in a
subform, minus error handling and a lot of lines that work fine. Neither of
the last two commands work, and I'm stumped.

Me.Net.SetFocus
Me.Net = Me.Gross * 0.85
Me.TrainerDue = Me.Gross - Me.Net

- lots of lengthy calculations eliminated here

Forms!frm_Monthly!AfterExpenses.SetFocus
Forms!frm_Monthly!AfterExpenses = Forms!frm_Monthly!NetRevenue -
Forms!frm_Monthly!MonthlyExpenses
'to this point everything works - I've tried lots of solutions, including
these:

Forms!frm_Monthly!subfrm_MP3History.Form![Net].SetFocus

'although the [Net] field on the subform is highlighted, focus remains on
[AfterExpenses] on the main form

DoCmd.GoToRecord acDataForm, "Forms!frm_Monthly!subfrm_MP3History", acNewRec
'(returns error message that subform isn't open)

Any thoughts?
 
B

Beetle

You need to set focus to the Subform Control first (the window
that holds the subform), then set focus to the the control on
the subform;

Forms!frm_Monthly!subfrm_MP3History.SetFocus
Forms!frm_Monthly!subfrm_MP3History.Form![Net].SetFocus

Keep in mind that the name of the Subform Control may, or may not,
be the same as the name of the subform itself, so if the above doesn't
work check the name of the Subform Control.
 
J

Jeri

Thank you, but I actually tried that already. Although the correct control is
highlighted, the cursor and the focus remain on the main form. And yes,
that's the name of the object. Might the problem be that it's on a tab? The
tab name is MP3Page.

Beetle said:
You need to set focus to the Subform Control first (the window
that holds the subform), then set focus to the the control on
the subform;

Forms!frm_Monthly!subfrm_MP3History.SetFocus
Forms!frm_Monthly!subfrm_MP3History.Form![Net].SetFocus

Keep in mind that the name of the Subform Control may, or may not,
be the same as the name of the subform itself, so if the above doesn't
work check the name of the Subform Control.
--
_________

Sean Bailey


Jeri said:
I hope someone has a suggestion here. I've struggled with this issue for an
embarrassing amount of time, and can't find any threads that help. I have
several subforms on several different tabs, with "on update" code that
recalculates fields on a main form. All that code runs fine, but I can't
persuade the focus to return to the subform. Here's the code that begins in a
subform, minus error handling and a lot of lines that work fine. Neither of
the last two commands work, and I'm stumped.

Me.Net.SetFocus
Me.Net = Me.Gross * 0.85
Me.TrainerDue = Me.Gross - Me.Net

- lots of lengthy calculations eliminated here

Forms!frm_Monthly!AfterExpenses.SetFocus
Forms!frm_Monthly!AfterExpenses = Forms!frm_Monthly!NetRevenue -
Forms!frm_Monthly!MonthlyExpenses
'to this point everything works - I've tried lots of solutions, including
these:

Forms!frm_Monthly!subfrm_MP3History.Form![Net].SetFocus

'although the [Net] field on the subform is highlighted, focus remains on
[AfterExpenses] on the main form

DoCmd.GoToRecord acDataForm, "Forms!frm_Monthly!subfrm_MP3History", acNewRec
'(returns error message that subform isn't open)

Any thoughts?
 

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