Solved

Can't Hide a Control that has Focus

Posted on 2014-10-13
6
574 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

708 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

12 Experts available now in Live!

Get 1:1 Help Now