I have a parent form with a data sheet subform containing records. The parent form has a button that modifies the selected subform record by calling a procedure on the subform. The current record number is stored in a variable, the procedure requeries the subform which removes the record, and then uses the variable to go to that record number (which in theory will go to the previous record available assuming it s not the first or last record). There can be 100 s of entries so it s important for the users that after the requery they aren t returned to the first record.
同一程序可以通过双重点击该次表上的任何领域。
相关守则:
Public Sub AddRemoveFromReport()
On Error GoTo ErrCheck
dblLineNo = Nz(Me.CurrentRecord, 1)
If Me.OnReport = True Then
Me.OnReport = False
Else
Me.OnReport = True
End If
Me.Requery
Me.Parent.frmPRJTrackerReportDetailTempOnReport.Form.Requery
Me.Parent.frmPRJTrackerReportDetailTempAvailable.Form.Requery
Application.Echo False
Me.Requery
DoCmd.GoToRecord acActiveDataObject, , acLast
DoCmd.GoToRecord acActiveDataObject, , acGoTo, dblLineNo
Application.Echo True
Exit Sub
ErrCheck:
Select Case Err.Number
Case 2427
MsgBox "Please select an item from the list before continuing.", vbOKOnly + vbInformation
Case 2105
// Last record selected, Go to the previous record instead
DoCmd.GoToRecord acActiveDataObject, , acGoTo, dblLineNo - 1
Application.Echo True
Resume Next
Case Else
MsgBox Err.Description
End Select
Application.Echo True
End Sub
When double clicking any fields on the record the code executes fine, but when executing the same code from the parent form the run time error occurs regardless of position within the recordset. The dblLineNo has the correct record number, it just seems to fail when attempting acGoTo.
I ve searched everywhere for an answer to this but haven t been able to find a solution. Any help would be greatly appreciated.