I have a field (myfield) in a subform (subform). My application sometimes sets the focus back on myfield after it has lost it. Since the focus could be in the main form (mainform), I set the focus first on subform before setting the focus on myfield. The below code fails at frm.SetFocus. What am I missing here? Thanks in advance.
‘this fragment code is executed when the focus is in myfield (subform) and the user clicks on a button in the ribbon. The code is actually executed inside the subroutine invoked by the ribbon button.
Dim ctr As Control
Dim subfrm As Access.form
Set ctr = Screen.ActiveControl ‘focus is in myfield which is in subform. Ctr points now to myfield
Forms!mainform!TextBoxInMainForm.SetFocus ‘focus is moved to a control in main form.
set subfrm = ctr.Parent ‘this correctly assigns subform to frm
frm.SetFocus ‘this triggers an error.
ctr.SetFocus ‘in order for this to work subform must have the focus first since myfield is in a
‘subform.
------------------------------------------------------------