G
Guest
I have a delete button in a form. I can get it to delete. Originally via Undo
by calling the menu options per someone's recommendation but that always
deletes the last record not current or selected record. So I've tried
'DoCmd.Record.Delete' or something like that which works and currently using
just RecordSet.Delete both with a acCmdRecordGoToNew or Last or Previous.
These delete the data but gotonew etc are 'not available at this time' and
without that the current form after deletion doesn't work. I start entering
new info but it disappears when I leave the fields and I can't get out of the
form because warnings for required data pop up. I need a way to delete the
current form record whether it's the first record entered for the day (data
entry form) or the last where after deletion it goes either to the next
record or if the last record was deleted to a new record. Typically the user
will need to clear the current form and start with a fresh form.
Private Sub Clear_Form_Button_Click()
On Error GoTo Err_Clear_Form_Button_Click
Dim iAns As Integer
iAns = MsgBox("Are you sure you want to delete this record?", vbYesNo)
If iAns = vbNo Then
Cancel = True
Else
Recordset.Delete
DoCmd.RunCommand acCmdRecordsGoToNew
End If
Exit_Clear_Form_Button_Click:
Exit Sub
Err_Clear_Form_Button_Click:
MsgBox Err.Description
Resume Exit_Clear_Form_Button_Click
End Sub
I've searched through other questions but haven't found anything that works.
Thanks in advance for you help!
Kristine
by calling the menu options per someone's recommendation but that always
deletes the last record not current or selected record. So I've tried
'DoCmd.Record.Delete' or something like that which works and currently using
just RecordSet.Delete both with a acCmdRecordGoToNew or Last or Previous.
These delete the data but gotonew etc are 'not available at this time' and
without that the current form after deletion doesn't work. I start entering
new info but it disappears when I leave the fields and I can't get out of the
form because warnings for required data pop up. I need a way to delete the
current form record whether it's the first record entered for the day (data
entry form) or the last where after deletion it goes either to the next
record or if the last record was deleted to a new record. Typically the user
will need to clear the current form and start with a fresh form.
Private Sub Clear_Form_Button_Click()
On Error GoTo Err_Clear_Form_Button_Click
Dim iAns As Integer
iAns = MsgBox("Are you sure you want to delete this record?", vbYesNo)
If iAns = vbNo Then
Cancel = True
Else
Recordset.Delete
DoCmd.RunCommand acCmdRecordsGoToNew
End If
Exit_Clear_Form_Button_Click:
Exit Sub
Err_Clear_Form_Button_Click:
MsgBox Err.Description
Resume Exit_Clear_Form_Button_Click
End Sub
I've searched through other questions but haven't found anything that works.
Thanks in advance for you help!
Kristine