Unable to SetFocus on a Main form control from Subform (1 Viewer)

abzalali

Registered User.
Local time
Today, 18:19
Joined
Dec 12, 2012
Messages
118
Dear Expert,
I'm using form with subform. Main form header contain a combobox. I need to check the combobox is null or not before update a subform filed. If combobox is null then its back to Main form combobox from subform. The code below that I'm trying to:
Code:
Private Sub AssignTo_BeforeUpdate(Cancel As Integer)
    If IsNull(Forms!frmDepartmentReview!cboDepartment) Then
        MsgBox "You must select Department first", vbInformation
        Forms![frmDepartmentReview]![cboDepartment].SetFocus
    End If
End Sub
Then I'm getting 2110 run time error
Access can't move the focus to the control cboDepartment.

Please help me.

Thanks
Mir
 

Extra_Cover

Registered User.
Local time
Today, 12:19
Joined
Oct 21, 2008
Messages
71
I have had similar problems. Try setting the focus to form first then set focus to control

Code:
Forms![frmDepartmentReview].SetFocus
Forms![frmDepartmentReview]![cboDepartment].SetFocus
 

abzalali

Registered User.
Local time
Today, 18:19
Joined
Dec 12, 2012
Messages
118
getting same error with this code:
If I press debug then go to the line:
Code:
Forms![frmDepartmentReview]![cboDepartment].SetFocus
 

Extra_Cover

Registered User.
Local time
Today, 12:19
Joined
Oct 21, 2008
Messages
71
Try removing the [] brackets.

Code:
Forms!frmDepartmentReview.SetFocus
Forms!frmDepartmentReview!cboDepartment.SetFocus
 

Users who are viewing this thread

Top Bottom