[AccessD] Error 2110: can't move the focus to control...

Stuart McLachlan stuart at lexacorp.com.pg
Wed Dec 26 15:25:10 CST 2012


In your Lost_focus you are trying to set_focus on one control while at the same time you are 
clicking on an image (setting focus) and setting focus to a different control during that event..

Triggering another  windows message/event inside an event handler can often cause 
problems like this.  

It's a bit like the old problem of changing text in a text box in the OnChange event. 

You are setting up  a conflict where Windows tries set the focus to two different controls at 
the same time.  TimeEntryNarrative (when the use clicks and sets the focus on the img) AND 
HoursBillable ( when the user's click causes the previous control to lose focus).

The problem is your attempt to control workflow by setting focus in the LostFocus event 
which is contrary to the whole concept of event driven as opposed to procedural 
programming.   The solution is : don't do that.  :-)

You can continue after you get the error with no problems because focus is no longer on the 
txtEdit, so the Lost_focus doesn't trigger and cause the same problem again. 
 

-- 
Stuart

On 26 Dec 2012 at 8:22, Rocky Smolin wrote:

> Dear List:
>  
> I am getting an error 2110: can't move the focus to the control...
>  
> It occurs in this code:
>  
> Private Sub imgGraphicForTimeEntryNarrative_Click()
>     Me.imgGraphicForTimeEntryNarrative.Visible = False
>     Me.TimeEntryNarrative.SetFocus
> End Sub
>  
> in the SetFocus line.  
>  
> After I get the error, if I press F5 the program carries on normally setting
> the focus to TimeEntryNarrative.
>  
> However, there is a condition that causes this.  Mostly clicking into
> imgGraphicForTimeEntryNarrative (which is a graphic OVER a text box.  The
> graphic shows if there's nothing in the text box and is made invisible when
> there is something in the text box), works fine.
>  
> But if the user clicks into one of two other text boxes and then clicks
> imgGraphicForTimeEntryNarrative, the error occurs.
>  
> Both those boxes have a LostFocus event as follows:
>  
> Private Sub txtEditWorkedTime_LostFocus()
>  
>     Me.cmdExit.SetFocus
>     Me.txtEditWorkedTime.Visible = False
>     Me.HoursBillable.SetFocus
>  
> End Sub
> 
> If I temporarily disable that module:
>  
> Private Sub txtEditWorkedTime_LostFocus()
> Exit Sub
>     Me.cmdExit.SetFocus
>     Me.txtEditWorkedTime.Visible = False
>     Me.HoursBillable.SetFocus
>  
> End Sub
>  
> then Private Sub imgGraphicForTimeEntryNarrative_Click() works.
>  
> I'm not opposed to a quick fix or workaround for this.  But I have gotten
> this error before - does anyone know the general cause (or general
> solution)?  Odd that after I get the error I can resume code execution and
> it works!
>  
> MTIA
>  
> Rocky Smolin
> Beach Access Software
> 858-259-4334
> www.bchacc.com <http://www.bchacc.com/> 
> www.e-z-mrp.com <http://www.e-z-mrp.com/> 
> Skype: rocky.smolin
>  
> 
>  
>  
>  
>  
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 




More information about the AccessD mailing list