triggering an event when focus moves from a subform to a main form

  • Thread starter Thread starter Paul James
  • Start date Start date
P

Paul James

I'd like to run some VBA code when the focus moves from a particular text
box control in a subform to any control in a main form. I've been trying
every possible event in the main form, the subform, and the subform control
I can think of, and nothing seems to work. For example I've tried

On Exit and On Lost Focus for the subform control;
On Deactivate and On Lost Focus for the subform, and
On Open, On Load, On Activate, On Got Focus and On Click for the main form.

None of these run the code when I click on any control in the main form
after the focus had been on that subform control.

Can anyone tell me what event procedure (and for which object) I can use to
run my code whenever the focus moves from that subform control to any
control in the main form?

Thanks in advance,

Paul
 
Exactly what are you trying to accomplish once the focus moves from that
particular text box?
Popup a message?
Change the color of the Main form controls?
 
I'm using this form and subform to match corresponding records from two
different tables. This matching requires user intervention, because the
records aren't always identical. So the arrangement is this:

- The main form displays a single record from one table.
- The subform is a continuous form that displays all potentially matching
records from the second table. The record in the main form has a field
(AgentID) that is initially blank. When the user finds a matching record in
the subform, the user clicks in the AgentID field of that record in the
subform and clicks a command button (labeled "Copy Agent ID") in the main
form which copies the value in the currently-selected AgentID field in the
subform to the AgentID field of the single record in the main form.

When the user clicks in the Agent ID field of the subform, the "Copy Agent
ID" command button becomes enabled. The idea being that if the user entered
that control, it was done with the purpose of copying that Agent ID to the
corresponding field in the main form. When the user clicks the "Copy Agent
ID" command button, I disable it with "Me![control name].enabled = False"
until the user clicks another AgentID field, at which time that command
button becomes enabled again.

So I would like to have a means of disabling that command button any time
the focus leaves the Agent ID field in the subform.

Many thanks to anyone who has the patience to read this explanation.

Paul
 
GVaught asked:
Exactly what are you trying to accomplish once the focus moves from that
particular text box?
Popup a message?
Change the color of the Main form controls?

The short answer is that I would like to disable (gray-out) a certain
command button in the main form whenever the focus shifts away from the
subform. Can anyone tell me what event I can use to accomplish this?

Thanks in advance.
 
Back
Top