DeleteControl 方法

此頁沒有內(nèi)容條目
內(nèi)容

expandtri全部顯示

DeleteControl 方法從窗體中刪除一個指定的控件。

expression.DeleteControl(FormName, ControlName)

expression     必需。返回“應(yīng)用于”列表中的一個對象的表達式。

FormName     必需 String 型。字符串表達式,用于標(biāo)識包含要刪除控件的窗體或報表的名稱。

ControlName     必需 String 型。字符串表達式,用于標(biāo)識要刪除的控件的名稱。

說明

例如,假定有一個在每個用戶第一次登錄到數(shù)據(jù)庫時都必須執(zhí)行的過程??梢詫⒋绑w上按鈕的 OnClick 屬性設(shè)為該過程。當(dāng)用戶登錄且運行該過程后,就可以使用 DeleteControl 方法從窗體中動態(tài)刪除這個命令按鈕

DeleteControl 方法分別僅在窗體“設(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