Microsoft KB Archive/208862

= ACC2000: How to Use Code to Deselect Records in a Form or Subform =

Article ID: 208862

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q208862



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
This article shows you how to use Visual Basic code to cancel the selection of records in a subform.



MORE INFORMATION
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 </li> Save the Orders Subform form and close it.</li> Open the Orders form in Form view.</li> 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.</li></ol>

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.

<div class="references_section">