KevinBaker
New member
- Local time
 - Today, 04:14
 
- Joined
 - Aug 23, 2020
 
- Messages
 - 26
 
I've got a form with a Continuous Subform.  I've got a Delete button that will delete the currently  selected record on the subform.  Before the record is deleted I'm trying to get the ID of the previous record if one exist or the next record.  Of course if there is only one record in the subform, then there would be no ID.
I don't think I fully understand when I'm at the BOF or EOF. If I'm on the first record in the subform, the code fails.
	
	
	
		
 I don't think I fully understand when I'm at the BOF or EOF. If I'm on the first record in the subform, the code fails.
		Code:
	
	
	Private Sub cmDelTrans()
  Dim lngID As Long, lngPID As Long
 
  lngID = SF.A1IdNum
  SF.RecordsetClone.FindFirst "A1IdNum=" & lngID
    
  If Not SF.RecordsetClone.BOF Then
    SF.RecordsetClone.MovePrevious
    lngPID = SF.RecordsetClone.A1IdNum
  ElseIf Not SF.RecordsetClone.EOF Then
    SF.RecordsetClone.MoveNext
    lngPID = SF.RecordsetClone.A1IdNum
  End If
 
  If Not IsNull(lngPID) Then
    strSQL = "UPDATE tblAccount1 SET Balance=Null WHERE A1IdNum=" & lngPID & ";"
    db.Execute strSQL, dbFailOnError
  End If
 
  'Delete the selected entry and any children records
  db.Execute "DELETE tblAccount1.*, A1IdNum, COfA1IdNum FROM tblAccount1 WHERE A1IdNum=" & lngID & " OR COfA1IdNum=" & lngID & ";"
End Sub