Solved

Can't Hide a Control that has Focus

Posted on 2014-10-13
6
591 Views
Last Modified: 2014-10-15
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
Comment
Question by:acramer_dominium
6 Comments
 
LVL 12

Expert Comment

by:jkaios
ID: 40378497
Try setting the focus on the form instead to avoid the error before hiding the controls on the form.

Me.SetFocus
0
 
LVL 30

Accepted Solution

by:
hnasr earned 250 total points
ID: 40378604
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
 
LVL 57
ID: 40378633
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 40379046
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
 

Author Closing Comment

by:acramer_dominium
ID: 40382783
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
 
LVL 30

Expert Comment

by:hnasr
ID: 40382879
Welcome!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now