troubline hiding sub form

G

Guest

Hi all:

I have an Access form with several sub forms. A user can select items from
any sub form to be included in yet another (different) form. Once the user
has selected an item it is removed from that sub form. If the count of
items on a particular sub form reaches 0, I want that sub form to be
hidden. But during the process I hide all subforms as the base sql is
refreshed. Then, when that happens, the sub forms become visible ONLY if
they contain data.

The problem is this: the code works fine as long as the user scrolls
through the main form. Sub forms appear and disappear according to their
data content. But once a user clicks on an item in a sub form to move it,
the code to hide it generates an error that says I cannot change the
visibility of a control if it has focus.

Ok, so I tried setting the focus to the main form *before* making the two
sub forms invisible so I could tell focus wouldn't be on either before
attempting to hide them:

Me.SetFocus '--- Code is run from module on main form.
Forms("frmAccessionReconciler").sbfrmFTLyophMatches.Visible = False
Forms("frmAccessionReconciler").sbfrmYPLyophMatches.Visible = False

I still return the error "Can't set visibility to false on a form that has
focus" even after I switch focus to the main form? I thought maybe it had
to do with quirks in the relationship between a main form and its sub forms
so I then tried opening a useless 'place holder' form and setting the focus
to that BEFORE calling Visible = False on the sub forms and *still* I get
the error about not hiding a form when it has the focus. I even added
this:

Forms("frmWhiteElephant").SetFocus
.... as the last line in the proc from sub form A that starts all the other
procs in motion. Still NG.

All I can think, at this point, is that since the procedure that launches
the chain of other procedures that finally terminates on the main form is
STARTED on the sub form I now want to hide, that's the issue.

In other words, I press a button on sub form A that launches a series of
procedures that call each other. The last procedure lives on the main form
and it attempts to hide sub form A. Is it possible that, since all these
actions originated from a proc on A that this is why it keeps telling me it
can't hide the sub form because it has focus?

Thanks
Kurt
 

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