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

ID: Q128257


The information in this article applies to:


SUMMARY

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

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.
  1. Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0).


  2. Open the Orders form in Form view.


  3. 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.


  4. Open the Orders Subform in Design view.


  5. 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.


  6. Save the Orders Subform and close it.


  7. Open the Orders form in Form view.


  8. 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.



REFERENCES

For more information about the Screen object, search the Help Index for "Screen object."

Additional query words: select de-select deselect


Keywords          : kbusage FmsHowto 
Version           : 2.0 7.0 97
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 9, 1999