Trying to hide control that has the focus

Bee

Registered User.
Local time
Today, 12:49
Joined
Aug 1, 2006
Messages
487
Hi,

I tried hiding a list control by setting its visible property to Flase in VB; however, it keeps returning a message: You can't hide a control that has the focus.

I don't know who to move the focus from my list control before hiding it. I searched in the MSDN online, but with no luck.

Any help will be very much appreciated.
Thanks,
B
 
I got this one a lot.

As long as you have another control on your form, you're fine.

Just before the line where you try to hide the control, add

[Forms]![form name]![name of another control].SetFocus

That will shift focus to the other control and let you hide the first one.
 
For forms where there is only one control or a case where all controls may be disabled, I usually create a unbound textbox, set its width and height to zero (effectively making it invisible), name it txtSetFocus and remove it from tab stop so user can't tab into it. I now have a control that I can use to enable/disable other controls.
 
Matt Greatorex said:
I got this one a lot.

As long as you have another control on your form, you're fine.

Just before the line where you try to hide the control, add

[Forms]![form name]![name of another control].SetFocus

That will shift focus to the other control and let you hide the first one.
Perfect, thanks.
 
I believe the overall form can also have focus if no other control is available.
 
Really? That'd be news to me.

Last time I tried that, I got an error saying that SetFocus isn't available at this time, IIRC.
 
Doc Man,

If there's a way of setting focus to the form itself, could you please post it as it would be very useful to have.

I've also tried this in the past, with no success.
 
I'm pretty sure the form itself can have focus, but perhaps it is because of parent/child form issues...

Also, it is possible to cheat in another way. You can have a text block that cannot be edited but still can gain focus. So create a title block that looks like a label but is really a text box. Lock it permanently, don't put it in the list of items that can be reached by tab, but you can still set focus to it.
 
The_Doc_Man said:
I'm pretty sure the form itself can have focus, but perhaps it is because of parent/child form issues...

Also, it is possible to cheat in another way. You can have a text block that cannot be edited but still can gain focus. So create a title block that looks like a label but is really a text box. Lock it permanently, don't put it in the list of items that can be reached by tab, but you can still set focus to it.

Yep :D, that was how I got around it.
Still, if there was an easy way to set to the form itself, I'd do that.
 

Users who are viewing this thread

Back
Top Bottom