Set focus using macro?

G

Guest

I have a Primary form and a subform within it.

I also have a pop up window which allows users to choose from a list of
codes, click on the code, and it populates the code in the SUBFORM. The
button that calls up the pop up window is on the Primary form.

The problem is, I want the focus to go to the next field on the subform
(datasheet view), but after the macro executes, the focus is back on the
primary form. is there a way I can get the focus to go to the next field in
the subform after the macro populates the subform instead of returning to the
primary form?

I don't want to stick the button in the subform, because its in datasheet
view, if at all possible.
 
S

Steve Schapel

Nathan,

You need to do it in three steps.

Action: GoToControl
Control: [NameOfYourSubform]

Action: GoToRecord
Record: New
<I presume this is what you mean?>

Action: GoToControl
Control: [NameOfFieldOnSubform]
 
G

Guest

Steve,
On the second step, I did not want a new record, but the next field in the
current record. I just substituted "Last" instead of "New".

However, it did not work. I get an error stating "There is no field named
"NameOfMySubform" in the current record". (of course, I changed the name to
the actual name of my subform)


Steve Schapel said:
Nathan,

You need to do it in three steps.

Action: GoToControl
Control: [NameOfYourSubform]

Action: GoToRecord
Record: New
<I presume this is what you mean?>

Action: GoToControl
Control: [NameOfFieldOnSubform]

--
Steve Schapel, Microsoft Access MVP
I have a Primary form and a subform within it.

I also have a pop up window which allows users to choose from a list of
codes, click on the code, and it populates the code in the SUBFORM. The
button that calls up the pop up window is on the Primary form.

The problem is, I want the focus to go to the next field on the subform
(datasheet view), but after the macro executes, the focus is back on the
primary form. is there a way I can get the focus to go to the next field in
the subform after the macro populates the subform instead of returning to the
primary form?

I don't want to stick the button in the subform, because its in datasheet
view, if at all possible.
 
S

Steve Schapel

Nathan,

This macro is running on an event on the main form, right? Check the
name of the actual subform control on the main form... it is not
necessarily the same as the name of the form which is being used as the
subform, hope you understand the distinction I am making here.
 
S

Steve Schapel

Nathan,

It's been a long time since I did this myself, so I'm not sure about
this. It could also be that you need to enter this in the control name
of the second GoToControl action:
[NameOfYourSubform].[Form]![NameOfFieldOnSubform]
 

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