Link to home
Start Free TrialLog in
Avatar of acramer_dominium
acramer_dominium

asked on

Can't Hide a Control that has Focus

Experts. I have a program where I am trying to hide all controls if an argument is met. The argument is met, I'm hiding all controls and I'm getting the error you can't hide a control that has focus (Source (textbox) ).

Just above this statement of hiding the control, I have the program setting focus to the close button. Seems to be ignoring the fact that I've set focus to the close button. txtSource never gets focus and is item 41 in tab control so I don't see how it's getting focus.

Any ideas?

If MarketType = 0 Or (MarketType = 1 And HomeCount = 0) Then
           
            Forms!frmLookUpIGL.Form.cmdClose.SetFocus
       
        'First Source Box: Hide
           
            Me.lblSource.Visible = False
            Me.Source1Box.Visible = False
            Me.Source.Visible = False
Avatar of jkaios
jkaios
Flag of Marshall Islands image

Try setting the focus on the form instead to avoid the error before hiding the controls on the form.

Me.SetFocus
ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This:

Forms!frmLookUpIGL.Form.cmdClose.SetFocus

Should be:

Forms!frmLookUpIGL!cmdClose.SetFocus

Assuming this is a single or parent form and the close button is on it, and frmLookup is the actual name of the form.

And if this code is running in that form, you can simply do:

Me.cmdClose.SetFocus

Jim.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of acramer_dominium
acramer_dominium

ASKER

This worked. I added an unbound text box on the form and set focus to that. I'm just going to make it blend in with the background. Thank you for the suggestions! I've never had this happen before.
Welcome!