Deleting record in subform

  • Thread starter Thread starter Jan Kronsell
  • Start date Start date
J

Jan Kronsell

I have a form with a subform in datasheet mode. I would like to select a
record in the subform, then deleting it, by pressing a button in the
mainform. My problem is, how to address the subform from the button, and to
tell it to delete the selected record.
Jan
 
Although this sounds picky, what you really want to do is delete a record
from a table, right? Asuming the table's primary key is available in the
subform (and if not, make it so) you can identify it as

Me![subform].form![PK]

and then use a statement like

DoCmd.RunSQL "DELETE * FROM MyTable WHERE PK = " &
Me![subform].form![PK]
 
and one more thing: you also need to requery the subform when you're done
deleting the record.
 
Thanks. I'll try that.

Jan'

Dave M said:
Although this sounds picky, what you really want to do is delete a record
from a table, right? Asuming the table's primary key is available in the
subform (and if not, make it so) you can identify it as

Me![subform].form![PK]

and then use a statement like

DoCmd.RunSQL "DELETE * FROM MyTable WHERE PK = " &
Me![subform].form![PK]

Jan Kronsell said:
I have a form with a subform in datasheet mode. I would like to select a
record in the subform, then deleting it, by pressing a button in the
mainform. My problem is, how to address the subform from the button, and to
tell it to delete the selected record.
Jan
 
Back
Top