Reputation: 1250
I have a really frustrating problem. Basically I have a mainForm with 3-4 subForms all in datasheet view. What is a generic way to REMOVE focus from subForm after a record is selected and set it to a control on mainForm?
I tried: OnCurrent Event:
Me.Parent.Form.SetFocus
Me.Parent.[Control].SetFocus
and it works half the time. The problem is, however, when user selects the record by clicking into some field in the subForm. Then the highlighted
fields are either A) the field in the subForm, B) the field in the mainForm. Decided seemingly at random.
How do I CANCEL/REMOVE the focus from the subForm completely before setting the new focus elsewhere?
Upvotes: 0
Views: 2788
Reputation: 1250
A workaround for this peculiar problem that solved it for me in the end was to make the field in the subForm look like a hyperlink (ie. user can "click" on it).
Then make an OnClick Event
which sets the correct focus, that is:
Public Sub [Field]_Click()
On Error GoTo Goto_Err
'some other code
Me.Parent.[Control].SetFocus
Goto_Exit:
Exit Sub
Goto_Err:
MsgBox Error$
Resume Goto_Exit
End Sub
This workaround is not ideal as the user has to click the field itself, rather than simply move to an another record by pressing up/down arrow.
Upvotes: 0
Reputation: 55906
That would be to move focus to a control on the parent form:
Me.Parent!SomeControl.SetFocus
Upvotes: 0