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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Record Button for Subform in Datasheet View 1

Status
Not open for further replies.

AaronMV

Programmer
Apr 18, 2006
15
US
I have an order form with a continuous subform in datasheet view. This subform displays items that are added to the order. If I right-click an item on the list, I can delete it. What I would like for my users is a "Delete Item" button that performs the same function. Any suggestions?

TIA,

AaronMV
 
If you put the delete item on the main form, you will need to ask the user to enter the ID of the record to be deleted. If you put the button on the subform, you will get a delete button on each line, but you will not have to ask the user for an ID. As an out of the way idea, you could use double-click with either just a confirm message or else a list of options.
 
Aaron,
Put command button on your main form and code something like:

**This code assumes the subform name is "Order_Details_Subform"

Private Sub DeleteItem_Click()
Me.Order_Details_Subform.SetFocus
With Me.Order_Details_Subform
DoCmd.RunCommand acCmdDeleteRecord

End With
End Sub
 
Remou,
How can I add the button in the subform to each line/record as you suggest? I added a command button to the form in design view, but it did not appear when I ran the form.
 
So sorry, I was not paying sufficient attention, I was thinking of a continuous form, but you said Datasheet View ... [blush]
 
Ok, I though a little and it seems to me that you could add a dummy field to the query on which your subform is based:
[tt]SELECT Members.Code, Members.Title, Members.FirstName, Members.LastName, [red]"Delete Rec" AS [DeleteRec][/red]
FROM Members;[/tt]
You could then assign a click event to the dummy field:
Code:
Private Sub DeleteRec_Click()
Dim strSQL
If MsgBox _
    ("Do you wish to deleted " & Me.Code & "?", vbYesNo) _
    = vbYes Then
    strSQL = "Delete * From Members Where Code=" & Me.Code 
    CurrentDb.Execute strSQL
    Me.Requery
End If
End Sub
Using Conditional Formatting to set the dummy field to, say, blue and underlined, would give the users an additional visual clue.
 
That's OK, I reformatted my subform based on your misread. The continuous form will work well for me.

Thanks Again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top