Why when open form focus goes to first field on a subform

I have a form that has a sub-form.  When the main form opens the focus is on the first field of the sub-form even though my openevent of the main form is

DoCmd.cmdCloseForm.setFocus

I've even tried setting the field on the sub form to no tab stop.

???
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin SparksCommented:
A long shot, but check the tab order of the main form and make sure that the subform itself is in the correct tab order place ( the subform is a control on the main form).

It appears that you're attempting to make the close button on the main form the focus when opening - I assume that it is enabled at that time? What happens if you don't set the focus at all - are their other controls on the main form that are available to receive the focus?


Kelvin
0
Rey Obrero (Capricorn1)Commented:
where is the command button located? in main form header or detail section?

if it is in the detail section, open the main form in design view,

from ribbon   Design > tools > Tab order

set the command button to have the highest tab priority

another way is
using the property sheet, in the OTHER tab set the tab Index of the command button to 0


.
0
SteveL13Author Commented:
It is in the footer section of the man form.  I've tried all suggestions and the focus still appears to be on the first field of the sub-form.  In case it matters, the subform is a datasheet form.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kelvin SparksCommented:
Where on the form is the subform?

Is the main form bound to a table or query? Does it have any controls bound to an underlying data source?


Kelvin
0
Rey Obrero (Capricorn1)Commented:
do this

- set the Tab stop property of the  subform  to NO

-set the tab Index of the command button to 0
0
SteveL13Author Commented:
Answers:

Where on the form is the subform?  - It's in the detail section of the main form.
Is the main form bound to a table or query?  -  It is bound to a table.
Does it have any controls bound to an underlying data source?  -  All of the controls are bound to fields in the bound table.

Also:

- set the Tab stop property of the  subform  to NO  -  I did that.
-set the tab Index of the command button to 0  -  I did that.

Also, when the form open it seems that the focus IS on the Close  button as you can see here (dotted border around the button)...

Close Button
But the first field on the sub-form "seems to be getting the focus also...

Subform
Am I just imagining things?

--Steve
0
Rey Obrero (Capricorn1)Commented:
can you upload a copy of the db with  objects relevant to this Q?
0
SteveL13Author Commented:
Attached.  When the Main Form opens, click [Open Subform] and you will see what I'm talking about.
Sample.accdb
0
Rey Obrero (Capricorn1)Commented:
you have codes in the load event of the subform that is causing the the first control to be highlighted, but the truth is, the command button has the focus.

try typing immediately when the subform is open, see if the information displayed is overwritten
0
Rey Obrero (Capricorn1)Commented:
... you have codes in the load event of the subform "subfrmDetail" that is causing the the first control to be highlighted, but the truth is, the command button has the focus.
0
Rey Obrero (Capricorn1)Commented:
here test this revised db.
added an unbound textbox txtDummy to the subform  "subfrmDetail"
Sample_rev.accdb
0
SteveL13Author Commented:
Rey,

I downloaded your revised database and see what you did. The I added am unbound textbox to my real subform and the first field is still "highlighted" in black when the form opens.  I must be missing something.

?
0
Rey Obrero (Capricorn1)Commented:
look at the codes in the Load event of  subform  "subfrmDetail"

i added a line to set the textbox "txtDummy" column width to 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
I see it.  That worked.   Thanks very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.