When I process the below code in an AfterUpdateEvent of a subform field, I get runtime error 97 (Object variable or With block variable not set).
The debug window marks the following line yellow:
OrigSelTop = SR.SelTop
FYI: I use Access97.
' Our class to hold a couple of Public vars
Private SR As clsSetRow
_____________________________________________
Private Sub Amount_AfterUpdate()
' Turn off screen redraw
Me.Painting = False
Me.Dirty = False
Dim OrigSelTop As Long
Dim RowsFromTop As Long
Dim OrigCurrentSectionTop As Long
' Must cache the current props because Requery will
' reset them
OrigSelTop = SR.SelTop
OrigCurrentSectionTop = SR.CurrentSectionTop
' Requery the Form
Me.Dirty = False
Forms![frmArticle]![subfrmDetails].Form.Requery
' Calculate how many rows, if any, the selected
' row was from the top prior to the Requery
' Check if Header is visible or not
If Me.Section(acHeader).Visible = True Then
RowsFromTop = (OrigCurrentSectionTop - Me.Section(acHeader).Height) / Me.Section(acDetail).Height
Else
RowsFromTop = OrigCurrentSectionTop / Me.Section(acDetail).Height
End If
' Setting the SelTop property forces this row to appear
' at the top of the Form. We will subtract the number of rows
' required, if any, so that the original current row remains
' at the original position prior to the Requery.
' First set the current record to the last record.
' This is required due to the method that
' that the Access GUI manages the ScrollBar.
Me.SelTop = Me.RecordsetClone.RecordCount
Me.SelTop = OrigSelTop - RowsFromTop
DoEvents
' Now setfocus back to the original row prior to the Requery
Me.RecordsetClone.AbsolutePosition = Me.CurrentRecord + RowsFromTop - 1
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub
The debug window marks the following line yellow:
OrigSelTop = SR.SelTop
FYI: I use Access97.
' Our class to hold a couple of Public vars
Private SR As clsSetRow
_____________________________________________
Private Sub Amount_AfterUpdate()
' Turn off screen redraw
Me.Painting = False
Me.Dirty = False
Dim OrigSelTop As Long
Dim RowsFromTop As Long
Dim OrigCurrentSectionTop As Long
' Must cache the current props because Requery will
' reset them
OrigSelTop = SR.SelTop
OrigCurrentSectionTop = SR.CurrentSectionTop
' Requery the Form
Me.Dirty = False
Forms![frmArticle]![subfrmDetails].Form.Requery
' Calculate how many rows, if any, the selected
' row was from the top prior to the Requery
' Check if Header is visible or not
If Me.Section(acHeader).Visible = True Then
RowsFromTop = (OrigCurrentSectionTop - Me.Section(acHeader).Height) / Me.Section(acDetail).Height
Else
RowsFromTop = OrigCurrentSectionTop / Me.Section(acDetail).Height
End If
' Setting the SelTop property forces this row to appear
' at the top of the Form. We will subtract the number of rows
' required, if any, so that the original current row remains
' at the original position prior to the Requery.
' First set the current record to the last record.
' This is required due to the method that
' that the Access GUI manages the ScrollBar.
Me.SelTop = Me.RecordsetClone.RecordCount
Me.SelTop = OrigSelTop - RowsFromTop
DoEvents
' Now setfocus back to the original row prior to the Requery
Me.RecordsetClone.AbsolutePosition = Me.CurrentRecord + RowsFromTop - 1
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub