Hide command button on lost focus

ssteinke

for what it's worth
Local time
Today, 04:35
Joined
Aug 2, 2003
Messages
195
Seems simple, but I haven't been able to crack this one.

I've searched and haven't found an obvious answer.

I want to hide a command button after it loses focus. I've tried placing this code on the On Lost Focus and On Exit events of the command button.

Code:
Me.cmdName.Visible = False

I get the 2165 error, 'Can't hide a control that has a focus'.

I guess one solution would be to force the focus to another control first, however, "how do I know what control the user is attempting to move the focus to?"
 
Hi ssteinke,
Do you want it to disappear when it looses focus under certain conditions or after it is pressed? If it is when pressed then *you* set the focus to another control of your choosing in the OnClick event and then set the button invisible.
 
thanks RG,

I'm trying to replicate an MS Outlook functionality. When the user clicks on a textbox, it makes the command button next to it visible. The user can tab to the button which, if clicked, will open a popup form allowing the user to format the textbox data.

However, if the user decides NOT to click the button and tabs off, I want the button to hide again.

A simple solution would be to set the focus to the next control in the tab index, but it just seems sloppy since a user could click on a different control instead of tabbing.

I'm sure i'm making myself clear as mud...

Scott
 
Hi Scott,
Having read many of your knowledgable responses to threads I suspected it was not as simple as I was making it out to be. The only thing that comes to mind is firing a timer event on the lost focus or exit event and letting the timer make the button invisible after some DoEvents and then turn itself off.
 
Thanks for the flattering remarks RG. As for the simplicity of this problem... I appreciate you thinking outside the box, but I absolutely can't believe there is no way to hide a command button after it loses focus without manually forcing the focus to a predetermined control, (it just seems i'm missing something very very simple).

Anyhow, i'll keep pluggin' away.

Scott
 
You can't hide any object that has focus. The only way is to set focus elsewhere first. It can be done but requires a fair bit of code.

The only other way (apart from rg suggestion which would be easier) i can think of is to set the onfous property on all objects to cmdbutton.visible = false except for the control that needs cmd box visible. That way if the user shits to another control it will hide.

i don't have any other suggestions

Ash
 
Ok, I played around with RG's idea, this actually seems to work pretty well without using tons of code.

In the LostFocus event of the cmdButton

Code:
    Me.TimerInterval = 1

In the OnTimer event of the form

Code:
If Me.cmdButton.Visible = True Then
     Me.TimerInterval = 0
     Me.cmdButton.Visible = False
End IF

It's these small details that sometimes frustrates me the most,... thanks for giving me a different outlook RG. You too Ash.

Scott
 
Glad to assist Scott. I'm sure you will return the favor.
 

Users who are viewing this thread

Back
Top Bottom