Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • Last Modified:

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
0
acramer_dominium
Asked:
acramer_dominium
2 Solutions
 
jkaiosCommented:
Try setting the focus on the form instead to avoid the error before hiding the controls on the form.

Me.SetFocus
0
 
hnasrCommented:
Try to add an unbound txtbox control make it small size. Set its Tab Index to 0, and Tab Stop to No. Enabled Yes, Locked Yes.
Let code Set focus to txtbox  and hide other controls.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You might try this - a trick I've been using for years - and works for many different scenarios:

Add a sliver of a text box on your form ... with border, back and fore colors matching what ever area you put in it.  Tab Stop = yes.  So, effectively, this control is .. for all practical purposes ... Invisible.

I use this all the time as a 'Focus Hold' ... when I need to disable controls. zzTxtFocusHold.  I always set focus to this control first ... then disable whatever control(s).  That way, I don't need to worry about that stupid error ... 'You can't set the focus ..."

I named it zztxtFocusHold ... so it sorts at the bottom of the controls list on the tool bar.

mx
0
 
acramer_dominiumAuthor Commented:
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.
0
 
hnasrCommented:
Welcome!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now