Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To cancel the selection of records, use the following statement:
Screen.ActiveControl.SetFocus
Although you may have selected multiple records in a subform, there is still one active control in the subform. Setting the focus to the active control is equivalent to pressing the TAB key or using the pointer to select the active control, which removes the current selection of records.
To cancel record selection on a subform, follow these steps:
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
- Start Microsoft Access, and then open the sample database Northwinds.mdb or the sample project NorthwindCS.adp.
- Open the Orders form in Form view.
- Select a record with multiple products.
- Select multiple records in the subform by holding down the SHIFT key and clicking the record selector button to the left of each Product field.
Notice that you can select more than one record at a time, and then close the form. - Open the Orders Subform form in Design view.
- In the form's Properties sheet, click the Event tab, and then create the following On Mouse Up event procedure:
Private Sub Form_OnMouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Screen.ActiveControl.SetFocus
End Sub
- Save the Orders Subform form and close it.
- Open the Orders form in Form view.
- Select a record with multiple orders. Hold the SHIFT key and click the record selector button to the left of each Product field.
Notice that records do not remain selected.
NOTE: When you cancel record selection in this way, you are also prevented from deleting records with the DELETE key, but you can still delete them by using the menu or toolbar.