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

delete button in continuous subform deleting the wrong record 1

Status
Not open for further replies.

stupiet

Programmer
Aug 21, 2001
176
0
0
US
To anyone who can help,

I have a mainform that contains employee information and in that form I have a continuous subform with employee points information.
I've added a delete button in the subform, that shows up on each row since it is continuous.
I've used a generic delete button that was created through the Access Wizard. When I click on the delete button, it always deletes the first record in the subform, never the record where the delete button is located.

This is the code obtained from the wizard. I'm assuming I need a different code but am not experienced enough to come up with it myself. Please help:

Private Sub btn_delete_Click()
On Error GoTo Err_btn_delete_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_btn_delete_Click:
Exit Sub

Err_btn_delete_Click:
MsgBox Err.Description
Resume Exit_btn_delete_Click

End Sub
 
Have you tried just using:
Code:
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
...to see what happens? What version of Access are you using?


HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
RuralGuy,

It seems to do the trick but the only problem is if the cursor is inside one record while you click on the delete button of another record, the one that the cursor is in get's deleted.

I guess I'll have to set the focus first before deleting. Thanks for the help!
 
Just tried it and it doesn't seem to work. When using setfocus method, the focus does not go to the line that you clicked the delete button on. Do you know of a way to get around it?

I'm using Access 2000.
 
I think i know what the problem was. I didn't use a button but a picture. When using a picture the focus does not shift to the record you want it to shift. Using a button it does. It just doesn't look as nice but I can live with that. Thanks for the help once again!
 
Set the focus to another control on *that* record like a TextBox. That should set the current record to the correct record.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top