Microsoft KB Archive/210596

= HOW TO: Use the DeleteControl and DeleteReportControl Statements, and the CreateGroupLevel Function in Access 2000 =

Article ID: 210596

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210596



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

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

IN THIS TASK
SUMMARY
 * DeleteControl and DeleteReportControl Statements
 * CreateGroupLevel Function



SUMMARY
This article shows you how to use the DeleteControl and DeleteReportControl statements and the CreateGroupLevel function. If you intend to write your own form wizard or report wizard, you can use these statements to delete controls on a form or a 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.

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.

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.

back to the top

DeleteControl and DeleteReportControl Statements
You can use DeleteControl and DeleteReportControl statements to delete a control that exists on a form or report in Design view. Both statements 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, and do not return a value. CreateGroupLevel is a function and can return a value as shown below.

To create a form, create a button on the form, display a message, and then delete the button on the form, follow these steps:  Start Microsoft Access and open the sample database Northwind.mdb. In the Database window, click Modules, and then click New to create a new module.  Type the following new procedure: Public Sub TestForm Dim MyForm As Form, MyControl As Control

Set MyForm = CreateForm                      ' create new form Set MyControl = CreateControl(MyForm.Name, 104) ' create command button on form MsgBox "About to Delete " & MyControl.Name DeleteControl MyForm.Name, MyControl.Name      ' delete button from form

End Sub   Tile the Microsoft Access and Microsoft Visual Basic Editor windows, and then step through the procedure by clicking anywhere in the following line Public Sub TestForm and pressing function key F8. To see the creation and removal of the command button, you need to restore the newly created form before executing the following statement: MsgBox "About to Delete " & MyControl.Name 

back to the top

CreateGroupLevel Function
When a report is open in Design view, you can create groups by using the CreateGroupLevel function, which has the following syntax CreateGroupLevel(ReportName$, Expression$, HasHeader, HasFooter) where:
 * ReportName$ is a string expression identifying the report.
 * Expression$ is a string expression representing the name of the field or calculated field that you want to group by.
 * HasHeader and HasFooter are the literals TRUE or FALSE that indicate whether the group includes a group header or group footer, respectively.

To use CreateGroupLevel, follow these steps:  Start Microsoft Access and open the sample database Northwind.mdb. Create a new report in Design view, based on the Customers table.</li> Add all fields from the Customers field list to the Detail section of the report.</li> Save the report as rptCustomerTest.</li> Preview the report and notice the record order.</li>  Create a new module and insert the following procedure: Sub NewGroup

Dim intGroupLevel DoCmd.OpenReport "rptCustomerTest", acViewDesign intGroupLevel = CreateGroupLevel("rptCustomerTest", "Country", True, False) MsgBox "Group created at level " & intGroupLevel

End Sub </li> On the Run menu, click Run Sub/UserForm.</li> Preview the report again, and notice the addition of the Country header and the sorting of the records by country.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 that indicates which level it created, beginning with zero. In the example above, CreateGroupLevel returns 0 because "Country" is the first group.</li></ol>

back to the top

Keywords: kbhowto kbhowtomaster kbprogramming KB210596

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.