office交流網(wǎng)--QQ交流群號及微信交流群

Access培訓(xùn)群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請用微信掃碼)

        

Access動態(tài)創(chuàng)建窗體及動態(tài)創(chuàng)建控件

2017-10-18 17:08:00
tmtony8
原創(chuàng)
8729

用過Access通用平颱的都知道。其主要功能就是根據(jù)記録源自動創(chuàng)建窗體及相關(guān)的設(shè)置

正常情況下我們都是先通過曏導(dǎo)或者設(shè)計視圖創(chuàng)建好相關(guān)的窗體給用戶使用。但是也有時需要讓用戶動態(tài)創(chuàng)建一些內(nèi)容

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

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

效果圖:


    分享
    文章分類
    聯(lián)繫我們
    聯(lián)繫人: 王先生
    Email: 18449932@qq.com
    QQ: 18449932
    微博: officecn01
    移動訪問