ACC2000: How to Use a Button to Hide and Display a Subform

ID: Q210600


The information in this article applies to:
  • Microsoft Access 2000

Novice: Requires knowledge of the user interface on single-user computers.

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


SUMMARY

You can hide and display a subform by using a command button or toggle button. This article shows you how to create either a macro or a sample user-defined function that uses a command button or toggle button to hide and display the Quarterly Orders subform on the Quarterly Orders form in the sample database Northwind.mdb. Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

The following steps demonstrate how to use a command button to hide and display a form.

Using a Macro

  1. Open the sample database Northwind.mdb.


  2. Create the following new macro, and then save it as Toggle Macro:


  3. 
       Macro Name      Action
       ------------------------
       Toggle Macro    SetValue
    
       Toggle Macro Actions
       --------------------------------------------------
       SetValue
       Item: [Quarterly Orders Subform].Visible
       Expression: Not [Quarterly Orders Subform].Visible 
  4. Open the Quarterly Orders form in Design view.


  5. Set the AllowEdits property of the form to Yes.


  6. Add a command button to the detail section on the form.


  7. Set the following properties for the command button:


  8. 
       Caption: Toggle Subform
       OnClick: Toggle Macro 
  9. View the form in Form view. Note that when you click the command button, the Quarterly Orders subform is hidden or displayed.


Using a User-Defined Function

  1. Open the sample database Northwind.mdb.


  2. Open the Quarterly Orders form in Design view.


  3. Set the AllowEdits property of the form to Yes.


  4. Add a command button or toggle button to any open area on the form.


  5. Set the following properties for the command button:
    
       Name: cmdToggle
       Caption: Toggle Subform
       OnClick: [Event Procedure] 
    Set the OnClick property of the command button to the following event procedure:


  6. 
    Sub cmdToggle_Click()
       Me![Quarterly Orders Subform].Visible = _
          Not Me![Quarterly Orders Subform].Visible
    End Sub 
  7. View the form in Form view. Note that when you click the toggle button, the Quarterly Orders subform is alternatively hidden and displayed.


Additional query words: togglebutton

Keywords : kbusage kbdta AccCon FmsEvnt FmsSubf FmsHowto
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.