在新窗体中创建一个窗体控件的代码-十段
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


在新窗体中创建一个窗体控件的代码

发表时间:2009/2/5 7:24:46 评论(1) 浏览(7217)  评论 | 加入收藏 | 复制
   
摘 要:下面的代码:首先基于“订单”表创建一个新窗体,然后使用 CreateControl 方法在窗体上创建文本框控件和附属标签控件。
注释  如果向导在新的或现有的窗体或报表中创建控件,它必须先在“设计”视图中打开窗体或报表。
正 文:
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



Access软件网交流QQ群(群号:198465573)
 
 相关文章
UMV快速平台出现“控件或子窗体控件放置在这个位置太大了”错误解决...  【缪炜  2013/6/7】
Access编译错误:用户定义类型未定义--Dim Nodinde...  【麥田  2013/6/14】
【Access小品】画龙点睛--图片控件运用示例  【煮江品茶  2013/7/21】
【VBA系统教程五】第三课 学习控件  【nivenm  2013/7/22】
常见问答
技术分类
相关资源
文章搜索
关于作者

十段

文章分类

文章存档

友情链接