Microsoft KB Archive/128257

= ACC: How to Use Code to Deselect Records in a Form =

Article ID: 128257

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q128257



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



SUMMARY
This article show you how to use Visual Basic for Applications code (or Access Basic code in version 2.0) to cancel the records that have been selected in a form by using the record selectors.



MORE INFORMATION
To cancel the selected records, use the following statement:

  Screen.ActiveControl.SetFocus

Although you may have selected multiple records in a form, there is still one active control in the form. 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.

The following example demonstrates how you can use this statement to prevent a user from selecting multiple records on a form.

 Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0). Open the Orders form in Form view. Move to a record with multiple orders. Select multiple records on the subform by holding the SHIFT key and clicking the record selector button to the left of each Product field (or Product ID field in version 2.0). Note that you can select more than one record at a time. Open the Orders Subform in Design view.  Set the form's OnMouseUp property to the following event procedure:

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

Private Sub Form_MouseUP (Button As Integer, Shift As Integer, X As _                               Single, Y As Single) Screen.ActiveControl.SetFocus End Sub

NOTE: The word Private does not appear at the beginning of the procedure in version 2.0.  Save the Orders Subform and close it.</li> Open the Orders form in Form view.</li> Move to a record with multiple orders. Select multiple records on the subform by holding the SHIFT key and clicking the record selector button to the left of each Product field (or Product ID field in version 2.0). Note that you cannot select more than one record at a time.</li></ol>

<div class="references_section">