报告限制中的条件格式 [英] Conditional Format in Report Limit

查看:63
本文介绍了报告限制中的条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VBA在报告中应用条件格式。我已创建代码以将格式应用于31个字段,名为Date1,Date2,... Date31,代表一个月中的31天,适用于数据库中的每个人。每个日期字段都设置为字符串,并且最多可以分配七个不同的代码,这些代码将使用条件格式代码在报告上以不同的颜色表示。


我写了一个for / next循环将条件格式应用于每个Date(#)字段,如果我只循环到12次,它的效果很好。如果我循环十三次或更多次,程序会在不同的字段上出错。错误meg:运行时错误''438'':对象不支持此属性或方法。


我在进入后逐个编码每个日期(#)字段Date13代码,它错误。


格式化12个字段后为什么会停止?


我试图附上一段代码(我看到最多有20行)但是这里有新的,我不知道我是否做对了。


I''m using VBA to apply Conditional Formatting in a report. I''ve created code to apply formatting to 31 fields called Date1, Date2, ...Date31 representing the 31 days of a month, for each person in a database. Each of the date fields are setup as strings, and can have up to seven different codes assigned, which will be indicated by different colors on the report using Conditional Format code.

I wrote a for/next loop to apply the conditional formatting to each of the Date(#) fields and it works great, if I only loop up to twelve times. If I loop thirteen times or more, the program errors out on different fields. Error meg: Run time error ''438'': Object doesn''t support this property or method.

I coded each Date(#) field individually and again, after entering into the Date13 code, it errors.

Why does it stop after formatting 12 fields?

I tried to attach a piece of the code (I see there is a max of 20 lines) but new here and I don''t know if I got it right.


展开 | 选择 | Wrap | 行号

推荐答案

这里的东西太少了在你的问题中感觉很难知道该说什么。


首先,为什么不在控件的设计中使用 ConditionalFormatting 而不是编码它们在你的 ???例程?


这个想法来自哪里只有20行代码?


我不知道为什么它停止格式化之后12个领域。我几乎不知道你在谈论什么,所以这并不是太令人惊讶。你已经明确地提出了很多问题,但是没有足够的考虑使它变得有意义(所以需要尝试但需要更多的努力)。


我建议你尝试一下首先是 ConditionalFormatting 的想法。如果这对你不起作用,请回来给我们提供一些比你目前为止更好的工作方式,我们会看到我们能做些什么。


PS 。图片中的所有彩色控件似乎都没有内容。作为一个例子,它似乎与你的问题中所说的一切相矛盾。这不会让任何人都能轻易理解你的目标。
There''s so little that makes sense in your question it''s hard to know what to say.

Firstly, why not use ConditionalFormatting in the design of the controls instead of coding them in your ??? routine?

Where does the idea come from that only 20 lines of code are possible?

I have no idea why it stops formatting after 12 fields. I have very little idea of what you''re talking about so that''s not too much of a surprise. You''ve put a lot into the question clearly, but not enough consideration to make it make much sense (so points for trying but more effort needed).

I suggest you try out the ConditionalFormatting idea first. If that doesn''t work for you, come back and give us something better to work with than what you have so far and we''ll see what we can do.

PS. All the coloured controls in your picture appear to have no contents. As an example it seems to contradict everything said in your question. That won''t make it easy for anyone to understand what you''re after.


首先,感谢您试图帮助我。我抱怨不太清楚。这是第一次尝试为条件格式编写报告,所以我可能没有以正确的方式进行,但我确实得到了所需的结果,如附件中所示。如果有更好的方法,我会非常感谢你的帮助。


为了回答你的第一个问题,我这样做是为了开始,但它只接受3个条件控制。我对每个控件有7种不同的条件,根据应用于表中每个字段的代码产生7种可能的颜色。


对于你的第二个问题,在这里是全新的我跟着关于输入程序员代码的说明,当我点击提出问题时显示按钮。它告诉我在代码指示符之间输入代码,并将代码限制为20行。如果我可以输入更多,我将提供整个代码,因为它是我给的两倍而不是那么大。


至于剩下的,WOW。我试图说清楚,但我显然不太善于沟通。作为基础,我将附上报告的设计视图。你已经有了最终的输出图片,我将包括报告的整个代码。


我有一个报告正在使用的表,有33个字段,首先是 ;姓名"字段长度为30,并且31个字段表示一个月中的31天,每个字段都是字段长度为2的字符串,并且填充有先前通过其他几个程序建立的代码。这31个字段中的每一个都是Date1,Date2,Date3等,通过Date31。并且lastfield是Month Selected,字符串长度为10.所有字段都是字符串。


在附加的Report Design View中,您将看到上面列出的每个表字段的控件。这会在报表中为表中的每个人创建一条线,以及先前分配给31个控件中每个控件的代码。并非所有31个控件都会分配数据。


我试图生成的是一个矩阵,通过读取分配给31个控件的代码并更改前景和背景颜色来生成纯色,由指定的代码决定(LL =黑色,PA =青色,PS =黄色,AS =洋红色,P =绿色,A =蓝色,S =红色,如提供的代码所示)大部分表格字段用P填充,并且只有Date1控件具有所有代码的示例,由所提供的报告输出示例的第一行中的所有颜色显示。


使用循环来寻址31日期中的每一个。控件,我能够成功地在表的字段中为代码发布适当的颜色,但正如所说,当它进入第13个循环或报告的第13天时,Access 2007会抛出先前声明的错误。表中的大多数字段填充有P字段。将在报告中显示为绿色块,或P。将显示代码未执行以更改颜色的位置。哦,如果该字段是空白的,则Else字段为空白。声明将颜色更改回黑色前景和白色背景。如果没有此语句,则前一种颜色会复制。

First, thanks for attempting to help me. I apoligize for not being more clear. This is the first time trying to code a report for Conditional Formatting, so I may not be doing it the right way, but I did get the desired results, as shown on the attachment. If there is a better way, I would be most grateful to you for your assistence.

To answer your first question, I did that to start with, but it only accepted 3 conditions per control. I have 7 different conditions for each control, producing 7 possible colors depending on the codes applied to each field in the table.

To your second question, being brand new here I was following the instructions about entering programmers code, which was displayed when I clicked on the "Ask a Question" button. It told me to enter the code between the code designators, and to limit the code to 20 lines. If I can enter more, I''ll supply the entire code as it is about double what I gave and not that big.

As for the rest, WOW. I tried to be clear, but I obviously am not very good at communicating. As a foundation, I''ll attach a Design View of the report. You already have the final output picture and I''ll include the entire code for the report.

I have a table that the report is using, that has 33 fields, first is "Name" with a field length of 30, and 31 fields representating the 31 days of the month, each are strings having a field length of 2, and are filled with codes previously established through several other programs. Each of these 31 fields are names Date1, Date2, Date3, etc., through Date31. And the lastfield is Month Selected for a string length of 10. All fields are string.

On the Report Design View attached, you will see a control for each of the table fields listed above. This creates a line on the report for each individual in the table, along with the codes previously assigned to each of the 31 controls. Not all of the 31 controls will have data assigned.

What I am attempting to produce is a matrix by reading the code assigned to the 31 controls and change the foreground and background colors to produce a solid color, which is determined by the code assigned (LL=Black, PA=Cyan, PS=Yellow, AS=Magenta,P=Green, A=Blue, S=Red as shown in the code supplied) Most of the table fields are filled with "P"s and only the Date1 control has an example of all the codes, shown by all the colors on in the first row of the report output example supplied.

Using the loop to address each of the 31 "Date" controls, I am able to successfully post the appropriate colors for the code in the table''s field, but as said, when it goes into the thirteenth loop or Day 13 on the report, Access 2007 throws the error previously stated. The majority of the fields in the table are populated with a "P" the will be shown on the report as a Green block, or the "P" will show where the code didn''t execute to change the color. Oh, if the field is blank, the "Else" statement changes the color back to Black foreground and white background. Without this statement a previous color replicates.

展开 | 选择 | Wrap | 行号


Art502:

至于剩下的,WOW。我试图说清楚,但我显然不太善于沟通
Art502:
As for the rest, WOW. I tried to be clear, but I obviously am not very good at communicating



这就是我在第一篇文章之后坦率地说的话。并不是说这是一个批评,因为大多数人在说实话时都很穷。现在我已经看过你最近的帖子,我发现我必须稍微改变一下我的意见(大大阅读)。这似乎是一张清晰的图片,以及如果我们的思想付诸实践,如何传递信息的例子。为了达到这个程度的努力和清晰度,我可以更进一步(A因为我很好地回应了努力和B,因为它现在更容易理解我正在使用的东西)比我当前早些时候预期的要好,肯定。


首先,你可以忽略我的PS。我现在可以更清楚地看到没有矛盾。我只是误解了你的代码并且没有意识到因为正在设置前景背景颜色,但是值仍然没有显示出来。


接下来我想评论两个事件程序调用的单独程序的使用。我经常试图将这个概念传达给人们,但我很不习惯发现它已经证明了。进一步留下深刻印象。


现在我们更接近问题的关键。您有一行代码(第10行),它明确地将循环限制为相对于任何月份的前12天的前12列数据。我将在这与所报告的问题无关的基础上工作,你只是以这种形式展示代码,因为它是你已经可靠地工作的。

话虽如此,我会考虑重新编码那里的大部分内容,以使代码更容易满足您的要求(减少代码 - 减少工作量)。

That''s what I would have said, frankly, after the first post. Not that it''s much of a criticism as most people are pretty poor when it comes to that to be honest. Now I''ve seen your more recent post though, I find I have to change my opinion somewhat (read considerably). It seems to be a picture of clarity and an example of how transferring info can be done if our mind is put to it. For that level of effort and clarity I can go further with this (A because I respond well to effort and B because it''s now so much easier to understand what I''m working with) than I expected earlier in the day, for sure.

Firstly, you can ignore my PS. I can now see more clearly there was no contradiction. I simply misunderstood your code and failed to appreciate that as both foreground and background colours were being set, the value, though still there, would not show up.

Next I''d like to comment on the use of a separate procedure which is called by both of the event procedures. I so often try to get that concept across to people, but I''m quite unused to finding it already in evidence. Further impressed.

Now we get closer to the crux of the matter. You have a line of code (Line #10) which explicitly limits the loop to the first 12 columns of data relative to the first twelve days of any month. I will work on the basis that this isn''t related to the problem reported, and you only showed the code in this form as it''s what you''ve already got to work reliably.

Having said that, I would consider recoding much of what''s there anyway, to enable the code to match your requirements more easily (Less code - less effort).

展开 | 选择 | Wrap | 行号


这篇关于报告限制中的条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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