office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access動態創建窗體及動態創建控件

2017-10-18 17:08:00
tmtony8
原創
8132

用過Access通用平颱的都知道。其主要功能就是根據記録源自動創建窗體及相關的設置

正常情況下我們都是先通過曏導或者設計視圖創建好相關的窗體給用戶使用。但是也有時需要讓用戶動態創建一些內容

這裡創建一箇以“訂單錶”爲記録源,一箇文本框控件和標籤控件的窗體。

Sub NewControls()
    Dim frm As Form
    Dim ctlLabel As Control, ctlText As Control
    Dim intTextX As Integer, intTextY As Integer
    Dim intLabelX As Integer, intLabelY As Integer

    Set frm = CreateForm
    frm.RecordSource = "訂單錶"
    intLabelX = 200
    intLabelY = 200
    intTextX = 1500
    intTextY = 200
    Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", _
        intTextX, intTextY)
    Set ctlLabel = CreateControl(frm.Name, acLabel, , _
         ctlText.Name, "NewLabel", intLabelX, intLabelY)
    ' Restore form.
    DoCmd.Restore
End Sub

效果圖:


    分享