如何在Microsoft Access中动态加载,访问和卸载子窗体 [英] How to dynamically load, access and unload subforms in microsoft access

查看:220
本文介绍了如何在Microsoft Access中动态加载,访问和卸载子窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从ASP.NET过渡到Access中的编程,当我想到Access中的子窗体时,我习惯于根据Usercontrols进行思考.我想做的是允许用户单击按钮来加载包含控件的子表单,用户可以在其中输入其他数据.我将不胜感激任何信息或资源,这些信息或资源将有助于我理解MS Access中的操作方式-以及如何在子窗体中加载,卸载和访问数据.预先感谢

I am trying top transition from ASP.NET to programming in access and I am used to thinking in terms of Usercontrols when I think of subforms in Access. What I would like to do is allow user to click a button to load a subform that contains controls user can enter additional data into. I would appreciate any information or resource that would help me with understanding how this is done in MS Access -- how to load, unload and access data in the subforms as well. Thanks in advance

推荐答案

好吧,作为一般规则,此类子表单的加载是自动完成的,不需要您进行任何编码.因此,总的来说,最好不要担心此问题,并节省所有编码时间,以帮助您所在地区的贫困人口.

Well, as a general rule such loading of sub forms is done automatic and does not require any coding on your part. So you in general are best not to worry about this issue and save all that coding time for helping the poor and needy in your neighborhood.

但是,我应该指出,如果您在Access中构建Web表单,则仅在使用子表单时才动态加载这些子表单.因此,如果将子表单放在选项卡控件的后面,则将得到最终的Web表单(发布时它们是XAML表单,并且表单代码转换为JavaScript),然后该子表单会为您动态加载到浏览器中.毫无疑问,此设置的确可以使Web表单的加载速度更快.因此,对于Web表单,这种加载是动态的,并且是对Access Web表单的按需加载.

I should however point out that if you building web forms in Access, then the sub forms are dynamic loaded ONLY when they are used. So if you place a sub form behind a tab control, then the resulting web form (they are XAML forms when published and form code is converted into JavaScript), then the sub form is dynamic loaded for you into the browser. No doubt this setup does result in web forms loading a lot faster. So for web forms, such loading is dynamic and on demand for Access Web forms.

但是,我的猜测是您在谈论Access客户端表单而不是Access Web表单.在这种情况下,在客户端,加载时间相当快,很少担心或需要这样做,或者浪费开发人员的时间.

However, my guessing here is you talking about Access client forms and not Access web forms. Given that case, on the client side, load time is rather fast and is quite rare to worry or need or waste developer time on doing this.

但是,在某些情况下,例如必须加载5个子表格,并且这样的时间可能开始累加到用户可能开始注意到延迟的程度.在这种情况下,您可以动态加载子表单,并且可以通过设置子表单对象的source object属性来实现.

However, there are some cases, such having to load say 5 sub forms, and such time can start to add up to the point where a user might start to notice a delay. In this case, you can dynamic load a sub form, and you do this by setting the source object property of sub-form object.

因此请记住,子表单仅是控件",并不与实际表单相关.在大多数Access应用程序中,我看到此子表单控件的名称与子表单的名称相同,但不一定必须如此.

So keep in mind that a sub form is only a "control" and is not tied to an actual form. IN most Access applications I seen the name of this sub form control is the same name as the sub form, but it certainly does not have to be.

因此,要动态加载子表单(例如,当更改为表单上的其他选项卡时),代码如下所示:

So, to dynamic load a sub form, such as when changing to a different tab on a form, the code looks like this:

  Private Sub TabCtl2_Change()

     If Me.TabCtl2.Value = 1 Then
        If Me.frmListContacts.SourceObject = "" Then
           Me.frmListContacts.SourceObject = "frmListContacts"
        End If

  End Sub

因此,如果将子表单控件放置在表单上,​​但将源对象设置保留为空白,则不会为该子表单加载或显示任何表单.并且在上面,一旦我加载了表单,那么源对象设置将不会为空,因此,我不会尝试多次设置/加载子表单.

So, if you place a sub form control on a form, but leave the source object setting blank, then no form will be loaded or display for that sub form. And in the above, once I loaded the form, then the source object setting will not be blank, and thus I don't attempt to set/load the sub form more than once.

如前所述,在大多数情况下,加载表单时,无论如何都需要该子表单来加载和显示,因此在大多数典型应用程序中,不需要上述代码.

As noted, in the vast majority of cases when loading a form, you need that sub form to load and display anyway, so in most typical applications such above code is not required.

这篇关于如何在Microsoft Access中动态加载,访问和卸载子窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆