Set focus

R

redFred

Can someone explain why the following?

This works:
Me!Jobfrm!Invoicefrm.Form!cboTakenBy.BackColor = 15265264

This does not.
Me!Jobfrm!Invoicefrm.SetFocus
Me!Jobfrm!Invoicefrm.Form!cboTakenBy.SetFocus


The difference as I see it is only backcolor and setfocus. What's the magic?
 
M

Marshall Barton

redFred said:
Can someone explain why the following?

This works:
Me!Jobfrm!Invoicefrm.Form!cboTakenBy.BackColor = 15265264

This does not.
Me!Jobfrm!Invoicefrm.SetFocus
Me!Jobfrm!Invoicefrm.Form!cboTakenBy.SetFocus

The difference as I see it is only backcolor and setfocus. What's the magic?


Should be ok, but where you have the code is important
because there are events where the focus can't be moved.

Try moving the code to a different event.
 
R

redFred

Thanks Marshall. I have it attached to a command button on my Reservationfrm
( the "Me!" in my code, I subform up from Jobfrm.) The button sets up new
Invoicefrm and I am wanting to open with focus on that control.

Can you help me?
 
M

Marshall Barton

There's something funny here. A main form button's Click
event should be ok for changing the focus.

Looking more closely, I think there is something wrong with
the syntax. What is Jobfrm and what is Invoicefrm?

If Me is the main form, Reservationfrm, then it looks like
Jobfrm is a subform on the main form and Invoicefrm is a
subsubform within Jobfrm.

If that's what you have, then I can't explain why the
BackColor works (unless you are using A2K or an earlier
version). In any case, try using:

Me!Jobfrm.SetFocus
Me!Jobfrm.Form!Invoicefrm.SetFocus
Me!Jobfrm.Form!Invoicefrm.Form!cboTakenBy.SetFocus
 
R

redFred

Looks like I was failing to set focus in the correct step-down. Once I set
focus to Jobfrm first, it work as desired.

Thanks so much.

Marshall Barton said:
There's something funny here. A main form button's Click
event should be ok for changing the focus.

Looking more closely, I think there is something wrong with
the syntax. What is Jobfrm and what is Invoicefrm?

If Me is the main form, Reservationfrm, then it looks like
Jobfrm is a subform on the main form and Invoicefrm is a
subsubform within Jobfrm.

If that's what you have, then I can't explain why the
BackColor works (unless you are using A2K or an earlier
version). In any case, try using:

Me!Jobfrm.SetFocus
Me!Jobfrm.Form!Invoicefrm.SetFocus
Me!Jobfrm.Form!Invoicefrm.Form!cboTakenBy.SetFocus
--
Marsh
MVP [MS Access]

Thanks Marshall. I have it attached to a command button on my Reservationfrm
( the "Me!" in my code, I subform up from Jobfrm.) The button sets up new
Invoicefrm and I am wanting to open with focus on that control.
 
M

Marshall Barton

Well, yes, that was the specific problem, but I was also
trying to warn you that newer versions of Access require you
to use the .Form property when referring to a control
(including a subform control) on a subform. Omitting the
..Form property as you did has caused a lot of problems when
upgrading to a newer version of Access so it would be
advisable to fix those references now.
 

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