Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't Hide a Control that has Focus

Posted on 2014-10-13
6
Medium Priority
?
751 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 31

Accepted Solution

by:
hnasr earned 1000 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 58
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 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 31

Expert Comment

by:hnasr
ID: 40382879
Welcome!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

721 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