Solved Cannot setfocus on unbound control

Dell INSPIRON 6000
August 4, 2017 at 04:41:49
Specs: Microsoft Windows 10, 2.40 gigahertz Intel Core i5-4210U/8GB
(MSAccess 2007) I have a form that contains all unbound controls. When one of the controls loses the focus, I use VB to verify that the control contains valid data. If not, I want the VB code to return to that control so the user can correct it. I've tried both Form_SKPNum.SetFocus and DoCmd.GoToControl "Form_SKPNum" without success. Any ideas? Thanks.

message edited by stevezal


See More: Cannot setfocus on unbound control

Reply ↓  Report •

#1
August 4, 2017 at 10:08:43
The Setfocus works when used in the VB code executed when a button on the form is pressed, but not when the control on the same form loses the focus.

Reply ↓  Report •

#2
August 9, 2017 at 01:29:16
✔ Best Answer
The only workaround I can offer is to set focus to another object first, then set focus to the object you want to return to.

For example, I have three text boxes on my form.

Text2
Text4
Text6

I want to evaluate the content of Text2 to ensure it is not empty. If it is empty I need to setfocus to it, but to do that, I will first setfocus to Text6, then back to text2.

Private Sub Text2_LostFocus()
    If Forms!Form1.Text2.Text = Empty Then
        Forms!Form1.Text6.SetFocus
        Forms!Form1.Text2.SetFocus
    End If
    
End Sub


Reply ↓  Report •
Related Solutions


Ask Question