help to delete a record from the subform

pb21

Registered User.
Local time
Today, 22:43
Joined
Nov 2, 2004
Messages
122
I have a subform its not in datasheet view and gives details of bookings for clients.

I am using the on click event of a field and I know that access knows which record I clicked. How do I delete it? which method do I use. can it be done without searching as I know which one i clicked?

regards in advance.
:eek:
 
you can use DoCmd.RunCommand acCmdDeleteRecord
 
its a continuous form with record selectors and navigation not visible. will that be enough. also the rowsource for th subform is linked between two tables will that cause a problem or will cascade delete need to be set.
 
I used to put a Command Button alongside with the record and simply put

DoCmd.RunCommand acCmdDeleteRecord

in the code. Add confirmation MsgBox if you like. It deletes the record on the same row. How's that?
 

Attachments

  • DeleteRecord.jpg
    DeleteRecord.jpg
    11.4 KB · Views: 217
You can put a button on themain form as well (if you only want one button). You then access it by Me![SubForm Control Name].Form![Subform Primary Key]

So you couldh ave something like this...

Sub DeleteRecordButton_Click()

'Delete the selected record
dim strSQL as String
strSQL = "DELETE * FROM mytable WHERE mytblID = " & Me![mySubForm].Form![mytblID]

DoCmd.RunSQL strSQL

MsgBox("Confirmed")

End Sub

You could also put a form header on the subform with a delete button. Simply use the command button wizard and select delete record.

Hammy
 
You can put a button on themain form as well (if you only want one button). You then access it by Me![SubForm Control Name].Form![Subform Primary Key]

So you couldh ave something like this...

Sub DeleteRecordButton_Click()

'Delete the selected record
dim strSQL as String
strSQL = "DELETE * FROM mytable WHERE mytblID = " & Me![mySubForm].Form![mytblID]

DoCmd.RunSQL strSQL

MsgBox("Confirmed")

End Sub

You could also put a form header on the subform with a delete button. Simply use the command button wizard and select delete record.

Hammy

four years later, code saved my heiney !
 

Users who are viewing this thread

Back
Top Bottom