What is the correct procedure to move through records in a subform, stopping if at the first record?
Here is my code, which takes me from the [RemovedDate] control on the main form to the subform.
Private Sub RemovedDate_AfterUpdate()
On Error GoTo RemovedDate_AfterUpdate_Error
Call MsgBox(“Any existing Envelope #s will now be discontinued.” _
& vbCrLf & “” _
& vbCrLf & ” You will then be returned to Remarks” _
& vbCrLf & “in case you wish to enter reasons for removing this record.” _
, vbExclamation Or vbDefaultButton1, “Envelope #s to be Discontinued”)
Me.Form![tblEnvelopeNumbers subform].SetFocus
DoCmd.GoToRecord , , acLast
Me.Form![tblEnvelopeNumbers subform]!EndDate.SetFocus
If Me.Form![tblEnvelopeNumbers subform]!EndDate > Date Then
Me.Form![tblEnvelopeNumbers subform]!EndDate = Date
If Me.Form![tblEnvelopeNumbers subform]!AssignedTo = “A” Then
GoTo ProcessFinished
Else
DoCmd.GoToRecord , , acPrevious
If Me.Form![tblEnvelopeNumbers subform]!EndDate > Date Then
Me.Form![tblEnvelopeNumbers subform]!EndDate = Date
GoTo ProcessFinished
End If
End If
End If
ProcessFinished:
Me.Remarks.SetFocus
On Error GoTo 0
Exit Sub
RemovedDate_AfterUpdate_Error:
MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in procedure RemovedDate_AfterUpdate of VBA Document Form_frmTrinity”
End Sub
The above code works backwards from the last record in the subform (acLast) and works if there are only 2 records to which an EndDate needs to be applied. However, in the odd case there are 3 records which need an EndDate. But I can’t go back more than 1 record using this procedure. What I need is a test that says “if you’ve reached the first record, go to ProcessFinished.” I tried testing for acFirst (If acFirst Then…) but this produced erratic results.
Thanks.
Tom