Delete and Refresh on a subform

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Using Access XP.

I have a form that has a subform. The subform displays one column of a one
column table in datasheet view.

On the form I have a button to delete the current row on the subform.

Question 1: Is there an easy way to do this?

I currently am using a ado command to run a delete statement against the
data to delete the currently selected record. The problem I'm running into
is the record still displays in the subform. If I call the Requery method of
the subform immediately afterward, the record still displays. If I then move
to another record in the subform, the record that was deleted shows
"#deleted". If there is no easier method for deleting other than the one I'm
using then

Question 2: How can I get the display to refresh so the deleted record no
longer disappears.

TIA,.

Mike
 
On the form I have a button to delete the current row on the subform.
Question 1: Is there an easy way to do this?

I currently am using a ado command to run a delete statement against the
data to delete the currently selected record. The problem I'm running into
is the record still displays in the subform. If I call the Requery method of
the subform immediately afterward, the record still displays. If I then move
to another record in the subform, the record that was deleted shows
"#deleted". If there is no easier method for deleting other than the one I'm
using then

Question 2: How can I get the display to refresh so the deleted record no
longer disappears.

1) Why not simply use the delete command to delete the record from within the
form:

DoCmd.SetWarnings false
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings true

If you want the added security of being prompted prior to deletion, omit the
SetWarnings lines.

2) If you use suggestion 1, question 2 is moot.
 
Thanks, Bruce.

That doesn't work. It wants to delete the record for the form and not
the current record in the subform.

Mike
 
That doesn't work. It wants to delete the record for the form and not
the current record in the subform.

Oh, you didn't say that the button was on the main form. To delete the selected
record in the subform, precede the code that I gave you with code using the
following syntax:

'***
'Make sure the subform control was the last control to have
'the focus - if not, don't delete any records
If Screen.PreviousControl.Name <> SubformControlName then
MsgBox "You must select the record you wish to delete, first."
Exit Sub
End If
'We've come this far, so just do it.
Me.SubformControlName.Setfocus
'Here is where the original "delete" code would be located.
'***

Replace "SubformControlName" with the name of the subform *control* on the main
form (not the name of the subform, although both may share the same name).
 
Back
Top