I have a main form and a subform showing data from the same tables. The subform is shown in datasheet to display a list of records. The idea is that the user can use arrow keys in the subform to quickly see (and edit) all fields in the main form.
I found three problems. The first one was to find a suitable event, the one I found is "Form_KeyDown". So far so good. The second problem was that the focus was moved to the main form, solved by setting the subform's tab index to "0". Third, found out that the event is triggered for the current record, not the "landing" record in case of the Arrow up/down keys. So I solved by following:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
LngAbspos = Me.Form.Recordset.AbsolutePosition
if KeyCode = vbKeyDown Then
If LngAbspos < Me.Form.Recordset.RecordCount Then DoCmd.GoToRecord , , acNext
MainformRefresh me.evID
Me.Form.Recordset.AbsolutePosition = LngAbspos
End If
End Sub
Feels clumsy but seems to work. If there is a better way I would be happy to know. If not, hopefully this entry is useful to somebody facing the same issue.
I found three problems. The first one was to find a suitable event, the one I found is "Form_KeyDown". So far so good. The second problem was that the focus was moved to the main form, solved by setting the subform's tab index to "0". Third, found out that the event is triggered for the current record, not the "landing" record in case of the Arrow up/down keys. So I solved by following:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
LngAbspos = Me.Form.Recordset.AbsolutePosition
if KeyCode = vbKeyDown Then
If LngAbspos < Me.Form.Recordset.RecordCount Then DoCmd.GoToRecord , , acNext
MainformRefresh me.evID
Me.Form.Recordset.AbsolutePosition = LngAbspos
End If
End Sub
Feels clumsy but seems to work. If there is a better way I would be happy to know. If not, hopefully this entry is useful to somebody facing the same issue.