skip to next record after deletion

  • Thread starter Thread starter William Ortenberg
  • Start date Start date
W

William Ortenberg

I have a form using a query as record source. A button on the form will,
among other things, delete the current record. At the end of the code
behind the button, I attempt to go to the next record. However, instead,
the form fields are all populated with '#Deleted?' (from the current
record). Is there something I can do to get to the next record in this
scenario?

Thanks in advance.
 
Private Sub btnUpdMbr_Click()
On Error GoTo Err_btnUpdMbr_Click

<!-- Irrelevant code -->

'Delete record
strSQL = "DELETE * FROM Table " & _
"WHERE ID = " & ID.Value

CurrentDb.Execute (strSQL)

DoCmd.GoToRecord , , acNext 'Go to next record

Exit_btnUpdMbr_Click:
Exit Sub

Err_btnUpdMbr_Click:
MsgBox Err.Description
Resume Exit_btnUpdMbr_Click

End Sub
 
Try using the delete command for the current Record (of the Form) instead.
Something like:

DoCmd.RunCommand acCmdDeleteRecord

and Access will automatically remove the deleted Record from the Form's
RecordSource and make the next Record (if available) the current Record of
the Form.
 
Back
Top