Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access Access 97从VB创建对象_Ms Access - Fatal编程技术网

Ms access Access 97从VB创建对象

Ms access Access 97从VB创建对象,ms-access,Ms Access,在access 97中,是否可以使用VB向表单中添加一些元素,例如标题为“Hello Word”、高度为300、宽度为700的命令按钮?尝试以下操作: Function AddCommandButtonFunction() Dim btn As CommandButton DoCmd.OpenForm "TestForm", acDesign On Error Resume Next DeleteControl "TestForm", "NewButton" On Error GoTo l

在access 97中,是否可以使用VB向表单中添加一些元素,例如标题为“Hello Word”、高度为300、宽度为700的命令按钮?

尝试以下操作:

Function AddCommandButtonFunction()
Dim btn As CommandButton

DoCmd.OpenForm "TestForm", acDesign

On Error Resume Next
DeleteControl "TestForm", "NewButton"

On Error GoTo lberr
Set btn = CreateControl("TestForm", acCommandButton)

btn.Name = "NewButton"
btn.Caption = "Hello World!"
btn.Top = 500 'twips. 1 twip = 1/1440 in
btn.Left = 500 'twips
btn.Width = 2000 'twips
btn.Height = 500 'twips

DoCmd.Close acForm, "TestForm", acSaveYes
DoCmd.OpenForm "TestForm", acNormal

Exit Function

lberr:
    MsgBox Err.Description
End Function

请注意,只有在设计模式下才允许添加/删除控件(以编程方式),

是的,当然可以。你真正的问题是什么?您尝试过哪些内容,哪些不适合您?根据您尝试完成的内容,只需创建一个隐藏按钮,然后在运行时使用VBA显示/隐藏它可能会更容易。Me.CommandButton.Visible=True