Setting the focus to a field on a subform within a tab control

G

gaugust

I have a form called frmMain with a tab control called TabCtl0 and a subform
within the tab control called frmScreening. I would like to set the focus to
a field called txtserial when a new record is added. I have tried the
following 2 lines, but neither work:

[Forms]![frmMain]![frmScreening].Form![txtserial].SetFocus

and

Forms!frmMain!TabCtl0.Pages(1).txtserial.SetFocus

Would you know the proper syntax. Thanks.
 
M

Marshall Barton

gaugust said:
I have a form called frmMain with a tab control called TabCtl0 and a subform
within the tab control called frmScreening. I would like to set the focus to
a field called txtserial when a new record is added. I have tried the
following 2 lines, but neither work:

[Forms]![frmMain]![frmScreening].Form![txtserial].SetFocus


Where are you tring to do this?

If it's in the main form, try this:

Me.frmScreening.SetFocus
Me.frmScreening.Form!txtserial.SetFocus

If it's from inside the subform:

Me.txtserial.SetFocus
 
A

Analyst72

First set the focus to the subform frmScreening using this
Forms.Item("frmMain").Controls("frmScreening").SetFocus

Then set the focus the txtSerial control on frmScreening using this
Forms.Item("frmMain").frmScreening.Controls.Item("txtserial").SetFocus
 
B

boblarson

Hey Analyst72, did you know that you can use

Forms("frmMain").Controls("txtSerial").SetFocus

instead of adding the word Item into each of those?
--
Bob Larson
Access World Forums Super Moderator
____________________________________
Access 2000, 2003, 2007, SQL Server 2000, Crystal Reports 10/XI, VB6
WinXP, Vista


Analyst72 said:
First set the focus to the subform frmScreening using this
Forms.Item("frmMain").Controls("frmScreening").SetFocus

Then set the focus the txtSerial control on frmScreening using this
Forms.Item("frmMain").frmScreening.Controls.Item("txtserial").SetFocus


gaugust said:
I have a form called frmMain with a tab control called TabCtl0 and a subform
within the tab control called frmScreening. I would like to set the focus to
a field called txtserial when a new record is added. I have tried the
following 2 lines, but neither work:

[Forms]![frmMain]![frmScreening].Form![txtserial].SetFocus

and

Forms!frmMain!TabCtl0.Pages(1).txtserial.SetFocus

Would you know the proper syntax. Thanks.
 
G

gaugust

I am trying to do this in the main form. Using the code you provided it now
works. Thanks Marshall.

Marshall Barton said:
gaugust said:
I have a form called frmMain with a tab control called TabCtl0 and a subform
within the tab control called frmScreening. I would like to set the focus to
a field called txtserial when a new record is added. I have tried the
following 2 lines, but neither work:

[Forms]![frmMain]![frmScreening].Form![txtserial].SetFocus


Where are you tring to do this?

If it's in the main form, try this:

Me.frmScreening.SetFocus
Me.frmScreening.Form!txtserial.SetFocus

If it's from inside the subform:

Me.txtserial.SetFocus
 

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