如何在VBA中构建表单? [英] How to Build a Form in VBA?

查看:98
本文介绍了如何在VBA中构建表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Fellow贡献者,


我希望这是可能的,但我还没有在万维网上找到答案。

我有数据表视图中的子表单,其中包含其记录源的所有字段,在本例中为查询。

我的问题是,是否可以在VBA中清除子窗体上的所有字段和标签,然后将子窗体的recordsource更改为另一个查询,然后使用所有新的子窗体重新填充子窗体记录源的字段。


背景:

我正在构建一个QA应用程序,它将向QA资源显示数据以供查看,但根据数据,我需要显示不同的字段集。根据不同数据集的数量,我宁愿不为每个可能的数据集创建一个子表单,因为这将在20年代总计有可能进一步增长。


此外,如果你有一个比上面提到的更好的想法,欢迎任何和所有的想法。


任何帮助将不胜感激,

-AJ


PS虽然我已经花了几个月的时间来回答问题,但这是我的第一个问题,所以我知道我可能很沮丧。 = P

Hello Fellow Contributors,

I am hoping this is possible, but I have yet to find an answer in the world wide web.
I have a subform in datasheet view that contains all of the fields of its recordsource, which in this case is a query.
My question is, is it possible in VBA to clear out all fields and labels on the subform, then change the subform''s recordsource to another query, then re-populate the subform with all the new fields of the recordsource.

Background:
I am building a QA App that will display data to the QA resource for review, but depending on the data, I need to display different sets of fields. And based on the number of different datasets, I would rather not create a subform for each possible dataset, because this would total in the 20''s with the possibility to grow further.

Also, any and all ideas are welcome if you have a better one than the above mentioned.

Any help would be appreciated,
-AJ

P.S. Even though I have spent the last few months answering questions, this is my first question asked, so I know I probably suck at it. =P

推荐答案

你好AJ。可以在程序控制下修改表单或子表单的记录源以及为表单定义的控件的各个属性(例如,位置,字体,背景颜色等)。据我所知,在运行时添加控件是不切实际的,好像我没记错,这只能在相关表单的设计模式下完成。


我更喜欢设计子表单尽可能使用Access自己的设施 - 考虑我以外的人未来的维护。


我的一个表单是自动报告系统的一部分,以三种不同的方式输出数据。对于其中一个主形式不需要子表单。另外两种方式需要在相同的父子字段上链接不同的子表单。为了适应后者,我使用'on-current事件形式来测试一个值,该值告诉我应该使用哪种类型的子表单,然后将默认值(子表单中的子表单的源对象更改为默认值)如果维护者需要更改它,则在表单中嵌入另一个子表单,该表单存在于物理表单集合中。


下面的IF在两个子表单之间进行选择,如果涉及两个以上,则可以用SELECT CASE替换:

Hi AJ. It is possible to modify under program control the recordsource of a form or subform and the individual properties of the controls defined for the form (for example, position, font, background colour etc). Adding controls at run-time is not practicable as far as I know, as if I remember correctly this can only be done in design mode for the form concerned.

I prefer to design subforms using Access''s own facilities as much as possible - thinking of future maintenance by persons other than me.

One of my forms is part of an automated reporting system outputting data in three different ways. For one of those the mainform does not require a subform. The other two ways require different subforms linked on the same parent-child fields. To accommodate the latter I use the form''s on-current event to test a value which tells me what type of subform I should be using, then change the sourceobject of the subform embedded in the mainform from the default value (the subform which is embedded in the form) to another subform which is present in the physical Forms collection should a maintainer need to change it.

The IF below selects between the two subforms, and could be replaced by a SELECT CASE if more than two were involved:

展开 | 选择 | Wrap | 行号


@Stewart Ross Inverness


这就像我背后保留的选项之一口袋里,我在想,如果一切都失败了,我会创建一个充满所有可能领域的表格会隐藏那些不属于当前表单视图的字段。

@Stewart Ross Inverness


我使用数据表视图的原因是我认为所有选项的维护都很少,因为所有选项都是如此我要做的就是隐藏我不想看到的字段,订单照顾自己,而不必证明文件和标签的位置。


听起来像我的想法赢了有可能,我觉得这不可能,感谢你的帮助斯图尔特罗斯因弗内斯,我会牢记这一点,如果没有更好的想法曝光,我将会讨论一些事情这里。


-AJ
@Stewart Ross Inverness
This is something like one of the options I was keeping in my back pocket, I was thinking if all else fails, I would create a form full of all possible fields then I would hide those fields that do not belong in this current form view.

@Stewart Ross Inverness
The reason I am using datasheet view is that it is as low maintenance of all options in my opinion, because all i have to do is hide the fields I don''t want to see and the order takes care of itself without having to justify the fileds and label positions.

Sounds like my idea won''t be possible, which I felt it wouldn''t, thanks for your assistance Stewart Ross Inverness, I will keep this in mind and if no better ideas come to light I will go with something discussed here.

-AJ


使用与斯图尔特方法类似的东西,你可以在模板中设置一定数量的未绑定字段然后,当您在父表单中选择密钥数据时,您可以运行以下代码:


a)Cha将子表单的记录源发送到你想要的任何查询(记录集)。

b)创建一个克隆来枚举该记录集中的字段。

c)设置每个的控制源记录集的字段的适当字段。

d)使所需的字段#可见,任何额外的字段都不可见。


这样的东西:

Using something similar to Stewart''s approach, you could set up a certain number of unbound fields in a template, then, when you select the key data in the parent form you may be able to run code that would:

a) Change the recordsource of the child form to whatever query (recordset) you want.
b) Create a clone to enumerate the fields in that recordset.
c) set the controlsource of each appropriate field to the recordset''s field.
d) make needed # of fields visible and any extra fields invisible.

something like this:

展开 | 选择 | Wrap | 行号


这篇关于如何在VBA中构建表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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