|
下面的示例创建带有命令按钮的窗体,并且显示提示信息询问用户是否要删除这个命令按钮。如果用户单击“是”,则该命令按钮被删除。
Sub eleteCommandButton()
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
|
|