vba 访问连续表单——如何对每条记录进行个性化控制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1267081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access continuous forms -- how to individualize controls per record?
提问by nielsj
I have an Access form displaying a tiny amount of data for a certain type of record. Basically it just prints the name on the left and on the right has a bunch of Rectangle controls whose background color I change in the form's OnLoad() function, according to results from a query performed using that record's ID as parameter.
我有一个 Access 表单,显示某种类型的记录的少量数据。基本上,它只是在左侧打印名称,右侧有一堆 Rectangle 控件,根据使用该记录的 ID 作为参数执行的查询的结果,我在表单的 OnLoad() 函数中更改了它们的背景颜色。
This all worked fine, got my ID/name on the left and 31 boxes on the right, colored if that day of the month is reserved :) But needless to say that function can be completely arbitrary since it's code.
这一切都很好,左边有我的 ID/姓名,右边有 31 个框,如果一个月的那一天被保留,则有颜色:) 但不用说,该函数可以是完全任意的,因为它是代码。
Then I decided to switch to 'continuous form' as to display as many records/items as possible. But alas, it was not to be -- all boxes were colored according to the query/function performed for the first record only. I figured that might be because it's the OnLoad() but changing it to OnCurrent() did not do much either. As it turns out, or that's what I read, the Rectangle intances are shared over the entire form and if I change the BackColor for one of them it changes for that box for each record.
然后我决定切换到“连续形式”以显示尽可能多的记录/项目。但遗憾的是,并非如此——所有框都根据仅对第一条记录执行的查询/功能进行着色。我想这可能是因为它是 OnLoad() 但将其更改为 OnCurrent() 也没有太大作用。事实证明,或者这就是我所读到的,矩形实例在整个表单中共享,如果我更改其中一个的 BackColor,它会更改每个记录的那个框。
I want to be able to change this according to a query performed on a per-record basis. Is there any way? Up until now I've only been able to find conditional formatting (the feature that's nor available for rectangles nor seems to cater my exact needs?) and kludgy Access 97 text-box hacks.
我希望能够根据对每条记录执行的查询来更改此设置。有什么办法吗?到目前为止,我只能找到条件格式(该功能不适用于矩形,似乎也不能满足我的确切需求?)和笨拙的 Access 97 文本框技巧。
Thanks in advance :)
提前致谢 :)
回答by Smandoli
You may be coming from an HTML background, where rectangles would be a natural solution. They aren't in Access. I don't think they'll work for you (in fact, "kludgy" could describe the attempt in my humble opinion).
您可能来自 HTML 背景,矩形将是一个自然的解决方案。他们不在 Access 中。我认为他们不会为你工作(事实上,“kludgy”可以在我的拙见中描述这种尝试)。
You can however display an image. You'll keep an image for each status ready to call up. I've made visual displays this way. A little later I may be able to post some code, but I think you'll find this plays out pretty simply even if I don't.
但是,您可以显示图像。您将为每个状态保留一个图像,以便随时调用。我已经通过这种方式进行了视觉展示。稍后我可能会发布一些代码,但我认为即使我不这样做,您也会发现这很简单。
ADDED NOTE:I'm glad this looks like it will work for you. You are concerned about "instanced only once" in your comment below. Yes, that's true for rectangles which are unbound controls (because they are designed for mere ornamentation). But you'll be using an image control which is a bound control (see Remou).
补充说明:我很高兴这看起来对你有用。您在下面的评论中担心“仅实例化一次”。是的,对于未绑定控件的矩形来说确实如此(因为它们只是为了装饰而设计的)。但是您将使用一个图像控件,它是一个绑定控件(请参阅 Remou)。
回答by Fionnuala
All unbound controls in a continuous form will be the same; bound controls can be varied using conditional formatting.
连续形式的所有未绑定控件将相同;绑定控件可以使用条件格式进行更改。
回答by maxhugen
Change each rectangle to a text box, Control Source:
将每个矩形更改为一个文本框,Control Source:
=Iif(myConditionIsMet,"?????","")
The "?" is the Full Block character in Arial (asc 219).
这 ”?” 是 Arial (asc 219) 中的 Full Block 字符。