Hiding a control After it lost focus

D

dhstein

This should be a fairly simple and I would think a fairly common situation.
I have a control - let's call it "Control #1". The user clicks Control #1
and another control (Control #2) becomes visible. He uses the control #2
(combo box, text box, whatever) and when he's done he clicks another control
(Control #3) to do something else. I'd like to hide Control #2 at this
point.
Problem 1 If I use the lost focus event of Control # 2 I can't hide it.
Problem 2 If I set focus to some control (Control #99) then the user who
clicked Control #3 is now sitting on Control 99 - that's confusing.

The cumbersome way is to go to every control on the form and the first thing
it does is hide Control #2. I have a lot of controls and I would think there
is a better way. Anybody have a better way? Thanks.
 
C

Clif McIrvin

I'm curious to see what responses your post triggers ... from my limited
experience I'm not certain it's trivial.

What I have done in what seems to be perhaps a similiar situation is
change the font color of Control #2 from red (function not available) to
green (function available) ... I think that can be done in the lost
focus event. I've also read here that the font (and border?) can be set
to the background color which effectively hides the control.

HTH!
 
D

Douglas J. Steele

Try creating a function like:

Function HidePreviousControl()
On Error GoTo ErrHandler

Dim ctlPrev As Control

Set ctlPrev = Screen.PreviousControl
If ctlPrev.Name <> Screen.ActiveControl.Name Then
ctlPrev.Visible = False
End If

ExitHere:
Set ctlPrev = Nothing
Exit Function

ErrHandler:
Select Case Err.Number
Case 2467, 2483 ' "No previous control"
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume ExitHere

End Function

Call that function in the GotFocus of each control.
 

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

Similar Threads

hiding and showing control 2
HELP WITH TAB CONTROL - HIDING FIELDS 7
Setting a control to Visible=False 2
Objects, Forms, Me, ! , SetFocus etc. 6
Changing the focus 2
hide control? 6
error 2165 4
Lost Focus ! 4

Top