全部显示

DeleteReportControl 方法

       

DeleteReportControl 方法从报表中删除指定的控件。

expression.DeleteReportControl(ReportName, ControlName)

expression   必需。返回“Applies To”列表中的一个对象的表达式。

ReportName  必需 String 型。字符串表达式,用于标识包含要删除的控件的窗体或报表的名称。

ControlName  必需 String 型。 字符串表达式,用于标识将删除的控件的名称。

说明

DeleteReportControl 方法仅分别在窗体“设计”视图报表“设计”视图中才可用。

注意   如果正建立一个从窗体或报表中删除控件的向导,该向导必须先在“设计”视图中打开这个窗体或报表,然后才能删除控件。

示例

下面的示例创建带有命令按钮的窗体,并且显示提示信息询问用户是否要删除这个命令按钮。如果用户单击“是”,则会删除该命令按钮。

Sub DeleteCommandButton()
    Dim frm As Form, ctlNew As Control
    Dim strMsg As String, intResponse As Integer, _
         intDialog As Integer

    ' Create new form and get pointer to it.
    Set frm = CreateForm
    ' Create new command button.
    Set ctlNew = CreateControl(frm.Name, acCommandButton)
    ' Restore form.
    DoCmd.Restore
    ' Set caption.
    ctlNew.Caption = "New Command Button"
    ' Size control.
    ctlNew.SizeToFit
    ' Prompt user to delete control.
    strMsg = "About to delete " & ctlNew.Name &". Continue?"
    ' Define buttons to be displayed in dialog box.
    intDialog = vbYesNo + vbCritical + vbDefaultButton2
    intResponse = MsgBox(strMsg, intDialog)
    If intResponse = vbYes Then
        ' Delete control.
        DeleteControl frm.Name, ctlNew.Name
    End If
End Sub