Hide subform when it loses focus

  • Thread starter Thread starter JCB
  • Start date Start date
J

JCB

A form containing details of a training course contains a text box with
a comma-separated list of types of attendee the course would be
suitable for. This list is derived from a table of courses/attendee
types. All of this is working properly.

When the user clicks on the text box, I want a subform to open to allow
them to edit the list of attendee types for this course. And I can get
that to happen as well.

But when the user then clicks anywhere off the subform, or moves to a
different window, I want the subform to close - in much the same way
that the list of options opens and closes for a combo box on a web
page. This isn't working because the only event I seem to be able to
pick up is the subform's Exit event - at which point the subform still
has focus, and I can't set .Visible = False

Any ideas, please?
 
Whilst appreciating that the appearing/disappering subform looks good, it
sounds as if you are editing a list and then translating it to a csv string.
The primary function of a subform is to provide a linked list in a
one-to-many relationship. Trying to fit that data into something else is the
problem. You are using an inappropriate tool by using the test box.

If space on the form is the concern (the subform being somewhat larger than
the text field with csv content) then try adapting the layout to put the
subform on a tab dialog page - that usually solves the problem without any
fancy coding to maintain.
 
Actually, the text box is exactly what I wanted, because that's what
the users are used to and expect to see, but the subform is exactly the
right way to edit the data behind the text box. So I was very keen for
it to work that way.

Thanks for the suggestion - it's working quite well, though not exactly
what I wanted. The subform only disappears when the user clicks on a
different control - and the process of changing tabs means I can't find
out which control it was they clicked on - the clicked-on control never
triggers any events.

The only solution I can come up with is to put a test into every other
control on the form to see whether the subform needs hiding.

That being unreasonable, I've put a drop-down arrow next to the text
box (like on a combo box) to switch to page 1 of the tab control (which
contains the subform), and a OnExit procedure on the subform to switch
back to page 0. Then putting a hotspot control (which doesn't actually
need to do anything!) behind everything else on the page means I
(almost) get what I want. Now if I can just find out which control it
was the user was trying to click onto ...
 
Back
Top