Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Records in a subform from the parent? 1

Status
Not open for further replies.

Bretto

Technical User
Oct 17, 2001
59
AU
I want to be able to delete records in a subform by using the click event of a command button in the parent form.

I am able to select the record in the subform using the record selectors and press delete. This works fine!

is it posible to imitate the action of pressing the delete key, using a command button on the parent form?

Thanx
Bretto
 
First Set focus to the subform.
Then Select the record
Then Delete it. As Follows: (in Access '97)

'First Set focus to the subform.
Me![Contacts subform].SetFocus
' Then Select the record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
' Then Delete it
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
On a similar note...how could you highlight a row in a continuous form and delete the record by clicking a command button in the same subform? I recognize that you can right click and select delete but my users do not wish to do it this way...they'd rather be able to highlight a record and click a "Delete" button. What is the event called when a record is highlighted so I can add code to the onclick event that will allow me to delete all highlighted records.

Thanks
 
You already have(if you're using the standard toolbar) a delete button for deleting records. It's the red 'X' on the toolbar. Will it not suffice? The same button works for the record you're in no matter which form/subform/subsubform you're in.
 
this is a good idea however for some reason the delete record button on the tool bar is disabled?

Does anyone now how to enable it or why it might be disabled?
 
I noticed same thing Bretto...sometimes it's disabled and I can't see much of a pattern as to when or why this happens.
 
I worked it out!!! Woo Hoo for me!

To delete a record from a subform using a command button in the parent form.

create a function that:

1. Finds the key field value (intKeyValue) on the subform.

2. Run a delete query that delete's the record from the subforms records where [subform].[keyfield] = intkeyvalue

3. Call the function from both the Click event of the command button and the delete event of the subform.

Here is the code I used:.

Function.

Function deleteContact()

Dim db As Database
Dim intconid As Integer
Dim intDelMsg As Integer
Dim strConNam As String



intconid = Forms![customers].[SF_Contacts]!conID
strConNam = Forms![customers].[SF_Contacts].Form!Name

intDelMsg = MsgBox("Are you sure you want to permanently delete " _
& strConNam, vbYesNo + vbCritical + vbDefaultButton2, _
"Warning")

If intDelMsg = 7 Then
DoCmd.CancelEvent
Exit Function
Else

Set db = CurrentDb

db.Execute ("delete * from T_contacts where [T_contacts].[conid] =" & intconid)

db.Close
Forms![customers].[SF_Contacts].Form.Refresh
Forms!customers.Refresh
End If
End Function




Here is the command button click event..

Private Sub cmdDelCon_Click()
deleteContact
End Sub


Here is the subforms delete event.

Sub Form_Delete(Cancel As Integer)

deleteContact
DoCmd.CancelEvent

End Sub

I hope this is helpfull,

Cheers,
Bretto
 
Good work Bretto...I think I can use this as well...thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top