office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

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

Access动态创建窗体及动态创建控件

2017-10-18 17:08:00
tmtony8
原创
8131

用过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

效果图:


    分享