Who can solve this puzzle?

evanscamman

Registered User.
Local time
Today, 06:47
Joined
Feb 25, 2007
Messages
274
I have a simple puzzle to offer.


Attached is a small DB with a form and subform.
  • The subform is only allowed to be visible when it has the focus.
Seems so easy - but it may be harder than you think.
I have also included my 'solution', but I'm not really very happy with it...

Evan
 

Attachments

You solved it very well. Can't think of a shorter version.

*AND* it works doesn't it?
 
"The subform is only allowed to be visible when it has the focus."

What you've done doesn't really solve the "puzzle" you've posed! The subform isn't invisible until it has the focus; it's invisible until you set it's Visible property to True/Yes. In point of fact, the puzzle you've posed can't be solved, because an invisible object can never receive focus!
 
The reason I wasn't very happy with my solution is because I never was able to find a real 'Lost Focus' event that worked for the subform. The closest thing I could find was the 'On Exit' event - which fires before the form loses focus, so I had to use the Timer. To me this didn't seem very robust or professional.

Evan
 
Can't look at it at where I am but I know that I've had problem of disabling all controls on a form. In order to do that I had to have focus on something, so I created a textbox, set its width and height to 0, called it txtFocusHolder. It's effectively invisible to the users, even though it's still set as visible but whenever I need to disable all controls, I move the focus to that "invisible" textbox then do my thing.

Maybe that'll give you an idea.
 
Banana, that approach might work very well, but you still have the problem of triggering that event. That is the basis of the question here - how do you trigger a 'Subform Lost Focus' event.

Evan
 
A ugly hack:

In each of subform's control, have a Lost Focus event which all call a common sub which then query what control has the focus and whether it is in the subform. If the control/form with the focus isn't within that subform, then execute what you wanted to do for that "subform lost focus event"
 
Banana - not a bad idea, especially since the subform would not be dependent on the parent's code. (The subform is going to be used many times on different forms.) I'm not sure if it will work though, because even when the subform has lost focus, it still remembers the last control that had focus, and calls it the 'active control'.

Evan
 
Oh, really? I guess it's not really a Lost Focus event after all. They should call it "About to lose it" event. :p

Reading through the help, it looks like Exit is identical to LostFocus *except* for the fact that if you click on the other forms/reports, it is not fired. It only fires when you click on other control on the form. Therefore, you would have to set the main form to modal popup to force your users to click "Close" button to access other form, thus guaranteeing that Exit event for the subform will fire.
 
BTW, had a looky-see at your DB and had a better understanding of what you were trying to do.

I've always found Focus events to be nearly useless for this sort of thing. The only other way I can see around this without using timer event, which seems to work just fine (though I don't understand how it isn't going invisible when timer runs out...) is to have all controls on the parent form have their GotFocus event filled in to call a common sub to check whether the subform ever had focus (using subform's enter event and a boolean variable) and if so, to execute what you needed execute). But if you're going to have it all over places, it's too much work that timer thingy you did is probably the best solution.
 

Users who are viewing this thread

Back
Top Bottom