ACC: DeleteControl, DeleteReportControl, and CreateGroupLevel

Last reviewed: August 29, 1997
Article ID: Q93094
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

This article discusses the DeleteControl and DeleteReportControl statements and the CreateGroupLevel() function. If you intend to write your own Form Wizard or Report Wizard, you can use the commands to delete controls on a form or report that is available in Design view, and you can use the function to create groups on a report that is available in Design view.

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 your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

MORE INFORMATION

You can use DeleteControl and DeleteReportControl commands to delete a control that exists on a form or report in Design view. Both commands require a string value that represents the name of the form or report and a string value that represents the name of the control.

DeleteControl and DeleteReportControl are statements, not functions. They do not return a value.

The example below creates a form, creates a button on the form, displays a message, and then deletes the button on the form. To create the form, follow these steps.

In Microsoft Access 2.0, 7.0, and 97

   Dim MyForm As Form, MyControl As Control
   Set MyForm = CreateForm()
   Set MyControl = CreateControl(MyForm.Name, 104)
   MsgBox "About to Delete " & MyControl.Name
   DeleteControl MyForm.Name, MyControl.Name

In Microsoft Access 1.x

   Dim MyForm As Form, MyControl As Control
   Set MyForm = CreateForm()
   Set MyControl = CreateControl(MyForm.FormName, 104)
   MsgBox "About to Delete " & MyControl.ControlName
   DeleteControl MyForm.FormName, MyControl.ControlName

When you delete a control using DeleteControl or DeleteReportControl, there is no visual feedback that the control is gone if the form or report is not minimized. The control still appears as if it were not deleted even though you can not click it to give it focus. To make the deleted control disappear, you must repaint the form design window by minimizing it and then restoring it.

If you have a report available in Design view, you can create groups for it in a procedure by using the CreateGroupLevel() function. Here is the syntax for CreateGroupLevel():

   Function CreateGroupLevel(ReportName$,Expression$,
                             HasHeader$, HasFooter$)

ReportName is a string expression representing the report name.

Expression is a string expression representing the name of the field or calculated field that you want to group by.

HasHeader and HasFooter indicate whether the group includes a group header or group footer, respectively. The values are True and False.

When it runs, CreateGroupLevel() adds a group at the innermost level. For example, if one group already exists, CreateGroupLevel() creates a second group within the first group. CreateGroupLevel() returns a number indicating which level it created, beginning with zero. In the example just mentioned, CreateGroupLevel() returns 1 because it is the second group, and the first group was Group zero.

Keywords          : kbprg PgmHowTo PgmOthr RptLayou
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbinfo


================================================================================


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: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.