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

Last reviewed: May 14, 1997
Article ID: Q128257
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

SUMMARY

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

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

MORE INFORMATION

To deselect 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 mouse 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
Keywords : FmsHowto kbusage
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 14, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.