I am trying to execute following code to delete the current record but to my surprise, it does not delete the current record but the first record of the table
I am fail to understand the reason for the same.
Private Sub CmdDel_Click()
Dim dbs As Database
Dim rcd As Recordset
Set dbs = CurrentDb
Set rcd = dbs.OpenRecordset("Customer")
reply = MsgBox("Do you want to delete the record", vbYesNo)
If reply = vbYes Then
If rcd.EOF Then
ElseIf Not rcd.BOF Then
Me.CmdAdd.Enabled = True
Me.CmdSave.Enabled = False
Me.CmdDel.Enabled = True
Me.CmdUndo.Enabled = True
Any suggestion to overcome this problem will be highly appreciated.
However, but I would also like to refesh the form using Me.Refresh after deletion in such a way that if cursor is in last record it moves to previous record & if curosr is in top of the record, if moves to the next record.
This is normal if the form allows the addition of new records. In such case, when you continuously click on "Next Record" (the button with the right arrow in the navigation buttons) you finally reach an empty (new) record.
Here is a solution:
If Me.NewRecord = True Then
DoCmd.GoToRecord , , acLast
The navigation buttons are standard on any form, except if you explicitly disable them by setting the NavigationButtons property of the form to False. It does not have anything to do with the way you use Access, it's simply the way Access forms work.