Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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

↑ Back to the top


Summary

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

↑ Back to the top


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.

  1. Start Microsoft Access, and then open the sample database Northwinds.mdb or the sample project NorthwindCS.adp.
  2. Open the Orders form in Form view.
  3. Select a record with multiple products.
  4. 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.
  5. Open the Orders Subform form in Design view.
  6. 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
    					
  7. Save the Orders Subform form and close it.
  8. Open the Orders form in Form view.
  9. 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.

↑ Back to the top


References

For more information about the Screen object, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type screen object in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB208862, kbusage, kbhowto

↑ Back to the top

Article Info
Article ID : 208862
Revision : 3
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 245