deleting proper record on continuous subform

R

Randall Arnold

I have a subform set up as continuous to handle the many records in a
1-to-many relationship. I needed the ability to delete any of the records
and figured I could just add a button tied to a delete module and clicking
the one beside a record would delete that record-- wrong. No matter which
of the many records on the continuous subform I select, the first record is
always the one deleted.

My code is below:

Private Sub FailDelete_button_Click()
If Me.Recordset.EditMode = dbEditNone Then

' delete record(s) and requery--grab proper record!!!!
Me.Recordset.Delete
Me.Requery
Else

' cancel current operation
On Error Resume Next
Me.Recordset.CancelUpdate
Me.Undo
End If
End Sub

Any ideas what I need to do to get the right record to be deleted? First
time I've ever run across this and nothing I've tried has made a difference.

Thanks,

Randall Arnold
 
S

smk23

Randall:
I don't think you need any code to delete one of the records on the
continuous forms subform. Use the record selector to the left and hit the
"delete" button.
 
R

Randall Arnold

Well... there is no record selector. Not on this form.

Since it's a continuous form, the field controls are repeated. So is the
delete button I added. I *assumed* that pressing the delete button beside
the desired record let Access "know" that it was the instance to be
deleted-- but apparently Access does not distinguish. Apparently I can be
on the last record in the table, press the delete button inside that
grouping on the form and the first record is still deleted. The first
record is always deleted, no matter what.

I have to believe that there's *some* way to distinguish between the rowsets
that are represented in each section of a continuous form. I just can't see
how to do that.

Any other ideas?

Randall
 
R

Randall Arnold

I found code that works on the Access MVP site (slightly modified):

If Not (fDelCurrentRec(Me)) Then
MsgBox "Unable to delete record", vbExclamation + vbOKOnly, "Alert"
End If


Function fDelCurrentRec(ByRef frmSomeForm As Form) As Boolean
On Error GoTo Err_Section

With frmSomeForm
If .NewRecord Then
.Undo
fDelCurrentRec = True
GoTo Exit_Section
End If
End With

With frmSomeForm.RecordsetClone
.Bookmark = frmSomeForm.Bookmark
.Delete
frmSomeForm.Requery
End With
fDelCurrentRec = True
Exit_Section:
Exit Function

Err_Section:
fDelCurrentRec = False
Resume Exit_Section
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top