How to create controls at run time Access VB?

后端 未结 4 1871
终归单人心
终归单人心 2020-12-15 01:16

How can you create controls at run time with VB code in Microsoft Access? after some digging I found that this is possible with the CreateControl function. The

4条回答
  •  情歌与酒
    2020-12-15 02:02

    You might be only missing DoCmd.Restore, here is an example on how to dynamically create form, data bind it, and create controls, all in runtime.

    Sub NewControls()
        Dim frm As Form
        Dim ctlLabel As Control, ctlText As Control
        Dim intDataX As Integer, intDataY As Integer
        Dim intLabelX As Integer, intLabelY As Integer
    
        ' Create new form with Orders table as its record source.
        Set frm = CreateForm
        frm.RecordSource = "Orders"
        ' Set positioning values for new controls.
        intLabelX = 100
        intLabelY = 100
        intDataX = 1000
        intDataY = 100
        ' Create unbound default-size text box in detail section.
        Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", _
            intDataX, intDataY)
        ' Create child label control for text box.
        Set ctlLabel = CreateControl(frm.Name, acLabel, , _
             ctlText.Name, "NewLabel", intLabelX, intLabelY)
        ' Restore form.
        DoCmd.Restore
    End Sub
    

提交回复
热议问题