Deleting record in subform

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
 
D

Dave M

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]
 
D

Dave M

and one more thing: you also need to requery the subform when you're done
deleting the record.
 
J

Jan Kronsell

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
 

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