DeleteReportControl 方法從報表中刪除指定的控件。
expression.DeleteReportControl(ReportName, ControlName)
expression 必需。返回“應用于”列表中的一個對象的表達式。
ReportName 必需 String 型。字符串表達式,用于標識包含要刪除的控件的窗體或報表的名稱。
ControlName 必需 String 型。字符串表達式,用于標識要刪除的控件的名稱。
DeleteReportControl 方法僅分別在窗體“設(shè)計”視圖或報表“設(shè)計”視圖中才可用。
注釋 如果正建立一個從窗體或報表中刪除控件的向?qū)?,該向?qū)П仨毾仍?/span>“設(shè)計”視圖中打開這個窗體或報表,然后才能刪除控件。
下面的示例創(chuàng)建帶有命令按鈕的窗體,并且顯示提示信息詢問用戶是否要刪除這個命令按鈕。如果用戶單擊“是”,則該命令按鈕被刪除。
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