2011-08-27 48 views
1

在訪問97中,是否有可能使用VB添加一些元素到窗體,就像標題爲「Hello Word」,高度爲300和寬度700的命令按鈕?訪問97從VB創建對象

+0

是的,當然這是可能的。你真正的問題是什麼?你有什麼嘗試,什麼不適合你? –

+0

根據您要完成的內容,創建隱藏按鈕然後使用VBA在運行時顯示/隱藏它可能會更容易。 Me.CommandButton.Visible = True –

回答

0

嘗試以下操作:

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 

請注意添加/控制的刪除(程序)是只允許在設計模式