This article applies only to a Microsoft Access database (.mdb or .accdb).
You can accomplish this by using the SetWarnings method of the DoCmd object, but you may prefer to disable warnings for the entire application. To do that, you can use the SetOption method of the Application object. However, if you do so, you should also turn the warnings back on as the application quits.
To do this in a simple, one-form application, follow these steps:
- Start Access, and then create a blank database named TestRun.
- Import the Customers table from the Northwind.mdb sample database.
- Create a new form in Design view, and then add an unbound combo box to the detail section.
- Set the following properties for the combo box:
Row Source: SELECT DISTINCT Customers.Country FROM Customers ORDER BY Customers.Country;
- Add a command button to the detail section of the form and name it cmdDelete.
- Set the OnClick property of the command button to the following event procedure:
- Close the Visual Basic Editor.
- Save the form as DeleteCustomers, and then close it.
- Create a new query in Design view, and then add the Customers table.
- In Access 2002 or in Access 2003, click Delete Query on the Query menu.
In Access 2007, click Delete in the Query Type group on the Design tab.
- Drag the asterisk (*) from the field list to the first column of the query design grid, and then drag the Country field to the second column.
- In the Criteria row of the Country column, type the following:
- Save the query as qryDeleteCustomers, and then close it.
- Open the DeleteCustomers form in Form view.
- Select a country from the combo box, click the command button, and note the warning that appears. Click No in the warning dialog box.
- Open the form in Design view, and then on the toolbar, click the Code button.
- In the Code window, type or paste the following procedures:
Private Sub Form_Load()
Application.SetOption "Confirm Action Queries", 0
Application.SetOption "Confirm Document Deletions", 0
Application.SetOption "Confirm Record Changes", 0
Private Sub Form_Unload(Cancel As Integer)
Application.SetOption "Confirm Action Queries", 1
Application.SetOption "Confirm Document Deletions", 1
Application.SetOption "Confirm Record Changes", 1
- Close the Visual Basic Editor, and then save and close the form.
- Open the DeleteCustomers form, select a country, and then click the command button.
Note that no warning dialog appears.
ID d'article : 229802 - Dernière mise à jour : 30 oct. 2008 - Révision : 1