0
votes

I have a subform (continuous form) with a button on each row that filters the main form on that record when clicked. When I click the button, the focus on the subform jumps to the top (i.e. first record) of the subform. How can I make the focus stay on the record.

In other words, I click the button next to record 100, and the focus changes to record one on the subform (main form displays record 100 as intended). I want focus on subform to stay on record 100.

Here's the VBA code I'm using:

Private Sub select_record_button_Click()
Me.Parent.Form.Filter = "[ID]=" & Me.ID
Me.Parent.Form.FilterOn = True
End Sub

The above code is on the On Click event for the button on the subform.

1
Forms are not linked? Any other event code in main- or subform?BitAccesser
Sounds like replicating functionality of a Split form. Did you consider Split form?June7
Yes, it recreates a split form but I have two subforms. I ran into issues when trying to do that with a split form.Dread

1 Answers

1
votes

You could try this:

Hold the subform's .SelTop property to a variable before applying the filter, and restore once the filter has been applied.

It won't keep the selected record in the exact row but it will be the first record in the subform's visible area.

Private Sub select_record_button_Click()
    Dim t As Long
    With Me
        t = .SelTop
        With .Parent.Form
            .Filter = "[ID]=" & Me!ID
            .FilterOn = True
        End With
        .SelTop = t
    End with
End Sub