![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
I have a partial solution to my problem. When using the Delete record item directly from the Edit menu I discover that the Delete event is called for each selected record. This enables me to count how many records have been selected and then set my own message: Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer) If MsgBox("You are about to delete " & nDeletions & " plants" & vbCrLf & vbCrLf & "Are you sure?", vbYesNo, "Deleting plants") = vbNo Then Cancel = True End If Response = acDataErrContinue nDeletions = 0 End Sub Private Sub Form_Delete(Cancel As Integer) nDeletions = nDeletions + 1 End Sub Private Sub Form_Open(Cancel As Integer) nDeletions = 0 End Sub This works OK. However I would still like to provide a button on the Form. I thought that this would work: Private Sub deleteButton_Click() On Error GoTo Err_deleteButton_Click DoCmd.DoMenuItem acFormBar, acEditMenu, acSelectRecord, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, acDelete, , acMenuVer70 Exit_deleteButton_Click: Exit Sub Err_deleteButton_Click: If Err.Number <> 2501 Then MsgBox Err.Description, , Err.Number End If Resume Exit_deleteButton_Click End Sub but it only deletes one record. I tried removing the first line: DoCmd.DoMenuItem acFormBar, acEditMenu, acSelectRecord, , acMenuVer70 If I do this then nothing is deleted. When one uses the menu item directly, the system seems to know which records have been selected but when one uses code with DoMenuItem, you have to do the selection. There seems to be no way of selecting the whole group. Any suggestions? |
#4
| |||
| |||
|
|
The proper way to do deletions is to use a Delete query, not to try and use the antiquated DoMenuItem method. -- Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele Co-author: Access 2010 Solutions, published by Wiley (no e-mails, please!) |
#5
| |||
| |||
|
|
I have a continuous form. I can select a number of records by clicking on a record selector and then shift-clicking on another one. The whole group from the first to the second is selected. If I then select 'Delete record' from the Edit menu, I am asked if I wish to delete n records. Good! It works fine but I would like to perform the same activity by means of a button that I place on the form. If I create a button to delete a record with the help of the Control wizard I end up with code such as: DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 After sorting out the meaning of the magic numbers I get to: DoCmd.DoMenuItem acFormBar, acEditMenu, acSelectRecord, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, acDelete, , acMenuVer70 When I run this it only deletes one, not many, records. Furthermore, the help system informs me that the DoMenuItem has been replaced RunCommand!! However exploring the RunCommand gets me no further. By the way I am using Access 2000. The menu item seems to know that I have selected more than one record. How I can do this in code? |
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |