ACC: Using IsVisible Property to Show or Hide Report Controls

ID: Q130366

The information in this article applies to:

SUMMARY

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

Microsoft Access has an undocumented property named IsVisible for controls in a report. IsVisible takes a True or False value depending on whether or not the report control is being shown when its HideDuplicates property is set to Yes. By using code, you can take advantage of the IsVisible property to show or hide other controls in the report.

NOTE: The IsVisible property can be set only from the Print event of the report section that contains the control.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications" manual.

NOTE: Visual Basic for Applications (used in Microsoft Access version 7.0) is called Access Basic in version 2.0.

MORE INFORMATION

The method below demonstrates how you can use the IsVisible property to hide a line control when a text box is hidden because it contains duplicate values. By using this method, you can create a grouped report with the group header and first detail record on the same line.

 1. Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0).

 2. Create a blank report based on the Products table.

 3. Save the report as Report1.

 4. If it isn't already displayed, open the Default Text Box property
    sheet and set the AutoLabel property to No. (To open the Default
    Text Box property sheet, display the toolbox if it isn't already
    displayed, click the Text Box button in the toolbox, and then click
    the Properties button on the toolbar.)

 5. Add a line control to the detail section, and set the following
    properties for the control:

       Name: ALine
       Left: 0
       Top: 0
       Width: 4
       Height: 0

 6. Add a text box to the detail section, and set the following
    properties for the control:

       Name: CategoryID
       ControlSource: CategoryID
       HideDuplicates: Yes
       Left: 0
       Top: 0.1

       NOTE: In version 2.0, there is a space in Category ID.

 7. Add another text box to the detail section, and set the following
    properties for the control:

       Name: ProductName
       ControlSource: ProductName
       Left: 1.2
       Top: 0.1

       NOTE: In version 2.0, there is a space in Product Name.

 8. On the View menu, click on Sorting And Grouping.

 9. In the first Field/Expression row, select CategoryID and set the
    sort order to Ascending.

10. Set the Detail section's OnPrint property to the following event
    procedure:

       If Me![CategoryId].IsVisible Then
          Me![ALine].Visible = True
       Else
          Me![ALine].Visible = False
       End If

11. On the File menu, click Print Preview. Note that the line
    control is displayed only when the IsVisible property for the
    CategoryID control is true.

REFERENCES

For more information about the HideDuplicates property, search for "How to hide duplicates in a report," and then "HideDuplicates property" using the Answer Wizard from the Microsoft Access for Windows 95 Help menu.

For more information about the Visible property, search for "Visible Property," and then "Visible Property (Application Object)" using the Microsoft Access for Windows 95 Help Index.

Keywords          : kbusage RptLayou RptProp 
Version           : 2.0 7.0
Platform          : WINDOWS
Hardware          : x86

Last Reviewed: August 30, 1997