Getting focus off of a subform

  • Thread starter Thread starter Robert Nolty
  • Start date Start date
R

Robert Nolty

Hi all --

I have a subform on a form which is invisible most of the
time. When it is needed, it becomes visible. The user
edits a field or two and clicks a "DONE" button. At that
point I want the subform to become invisible again. The
problem is, as the user pushes the DONE button the subform
has focus, and I get an error trying to make the subform
invisible while it has focus. So I tried to use VBA to
move focus to a control on the parent form, but I keep
getting runtime errors saying "Access can't move the focus
to xxx". I'm guessing that SetFocus only works for
controls on the form (in this case subform) that currently
has focus. I also tried moving focus to the parent as a
whole,

Me.Parent.SetFocus

but, according to the documentation and I guess this is
what I see, that just gives focus to the last control on
the parent form which had focus, which is the very subform
I am trying to get focus away from.

Does anyone have any ideas?

Thanks,
Bob
 
Robert,

Use the Forms collection to get to a control on the main form. E.g.

Forms!frmMain!SomeControl.SetFocus

"SomeControl" would logically be the control that first gets the focus when
the main form is opened (if a forms/controls name containes spaces, include
braces e.g. [Some Control]).

HTH,

Neil.
 
-----Original Message-----

Use the Forms collection to get to a control on the main form. E.g.

Forms!frmMain!SomeControl.SetFocus

Hi Neil -- thanks for the suggestion, but I think it was
essentially equivalent to what I was already trying,

Me.Parent.SomeControl.SetFocus

(Me is the subform.) At any rate, I tried your syntax and
got the same result -- at the time the VBA statement
executes, it throws an error with the message "Microsoft
Office Access can't move the focus to the control
SomeControl".

If I put my "DONE" button on the parent form instead of
the subform, I can throw the focus to SomeControl and of
course I can make the subform invisible. But it doesn't
make any sense to put the DONE button for the subform on
the parent form.

Any more ideas?

Thanks!

Bob
 
Robert,

Where is the error occuring in your code? When forcus leaves the subform the
subform automatically gets saved, is there any validation rules or code that
may cancel the saving of the form (this would generate the error you
discribe). If this is not the case, post some code that you are using and
someone might be able to spot whats going on from that.

HTH,

Neil.
 
Back
Top