以连续形式更改不同记录的bg颜色 [英] Change bg colour of different records in continuous forms

查看:69
本文介绍了以连续形式更改不同记录的bg颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我一直在寻找网络&过去几天在这里的论坛,以帮助解决我的问题&让我自己真的很困惑..希望有人可以在这里帮助我。


我有一个连续的表格,每行有6个文本框,其中一个包含评估员的姓名(在另一个表格中)将为他/她分配特定颜色。


我要做的是循环连续记录表格,获取该记录的评估员的颜色值,&然后将该记录中所有文本框的背景颜色更改为该颜色。 (我希望这是有道理的)


我一直在努力用Recordset克隆做这个,然后尝试Me.Controls而不是......但到目前为止还没有运气。 (关于我是否应该使用Recordset或直接使用表单上的控件,我感到非常迷茫......?


这就是我所得到的那一刻(但我一直在改变它,所以这有点混乱):


Dim rs作为DAO.Recordset

Dim fld作为DAO.Field

Dim lngColour As Long

Dim ctl As Control


设置rs = Me.RecordsetClone

rs.MoveFirst


做的不是rs.EOF


如果不是IsNull(rs.Fields(" AssessorName"))那么


lngColour = DLookup(" [AssessorColour]"," Assessors"," [AssessorName] =''"& rs.Fields(" AssessorName")。Value&" ;''")


''以下不起作用...

''

For Each fld在rs.Fields

fld.Properties(" BackColor")。Value = lngColor

Next


''以下也不起作用 - 它会更改所有文本框在

''整个表格到lngColour! (永久性地,出于一些奇怪的原因?!)

''如何在1条记录中循环控制?

''

''For Each ctl In Me.Controls

''如果ctl.ControlType = acTextBox那么

''ctl.BackColor = lngColour

' '结束如果

''下一步ctl


结束如果


rs.MoveNext


循环


所以那里有两种不同的想法,既不对,也不是。我真的不知道我是否在正确的轨道上......任何帮助表示感谢!


提前致谢,

Karen

Hi there,

I''ve been searching the net & the forums here over the last few days for help with my problem & am getting myself really confused.. hoping someone may be able to help me here.

I''ve got a continuous form which has 6 textboxes in each row, one of which contains the name of an Assessor, who (in another table) will have a particular colour assigned for him/her.

What I''m trying to do is loop through the records of the continuous form, get the colour value for the Assessor for that record, & then change the background colour of all textboxes in that record to that colour. (I hope that makes sense)

I''ve been messing around trying to do this with Recordset clones, then trying Me.Controls instead.. but so far no luck. (I am very foggy on whether I should be using a Recordset or directly working with the controls on the form..?)

Here''s what I''ve got at the moment (but I keep changing it, so this is kinda muddled):

Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim lngColour As Long
Dim ctl As Control

Set rs = Me.RecordsetClone
rs.MoveFirst

Do While Not rs.EOF

If Not IsNull(rs.Fields("AssessorName")) Then

lngColour = DLookup("[AssessorColour]", "Assessors", "[AssessorName]=''" & rs.Fields("AssessorName").Value & "''")

'' the following doesn''t work...
''
For Each fld In rs.Fields
fld.Properties("BackColor").Value = lngColor
Next

'' following doesn''t work either -- it changes all textboxes on
'' the whole form to lngColour! (permanently, for some weird reason?!)
'' How do I just loop through the controls in 1 record?
''
'' For Each ctl In Me.Controls
'' If ctl.ControlType = acTextBox Then
'' ctl.BackColor = lngColour
'' End If
'' Next ctl

End If

rs.MoveNext

Loop

So there are 2 kinda separate ideas there, neither right, & I really don''t know if I''m even on the right track.. any help appreciated!

Thanks in advance,
Karen

推荐答案

嗨Karen


简单的答案是你不能在代码中进行条件格式化。你做的任何事情都会改变所有记录,而不仅仅是当前记录。


我会在表格上设置一个隐藏的文本框到Assessor颜色,并尝试相应地操纵条件格式。


Mary
Hi Karen

The simple answer is you can''t do conditional formatting in code. Anything you do will change all records and not just the current record.

I would have a hidden textbox on the form set to the Assessor colour and try to manipulate the Conditional Formatting accordingly.

Mary



你好,


我一直在搜索网络&过去几天在这里的论坛,以帮助解决我的问题&让我自己真的很困惑..希望有人可以在这里帮助我。


我有一个连续的表格,每行有6个文本框,其中一个包含评估员的姓名(在另一个表格中)将为他/她分配特定颜色。


我要做的是循环连续记录表格,获取该记录的评估员的颜色值,&然后将该记录中所有文本框的背景颜色更改为该颜色。 (我希望这是有道理的)


我一直在努力用Recordset克隆做这个,然后尝试Me.Controls而不是......但到目前为止还没有运气。 (关于我是否应该使用Recordset或直接使用表单上的控件,我感到非常迷茫......?


这就是我所得到的那一刻(但我一直在改变它,所以这有点混乱):


Dim rs作为DAO.Recordset

Dim fld作为DAO.Field

Dim lngColour As Long

Dim ctl As Control


设置rs = Me.RecordsetClone

rs.MoveFirst


做的不是rs.EOF


如果不是IsNull(rs.Fields(" AssessorName"))那么


lngColour = DLookup(" [AssessorColour]"," Assessors"," [AssessorName] =''"& rs.Fields(" AssessorName")。Value&" ;''")


''以下不起作用...

''

For Each fld在rs.Fields

fld.Properties(" BackColor")。Value = lngColor

Next


''以下也不起作用 - 它会更改所有文本框在

''整个表格到lngColour! (永久性地,出于一些奇怪的原因?!)

''如何在1条记录中循环控制?

''

''For Each ctl In Me.Controls

''如果ctl.ControlType = acTextBox那么

''ctl.BackColor = lngColour

' '结束如果

''下一步ctl


结束如果


rs.MoveNext


循环


所以那里有两种不同的想法,既不对,也不是。我真的不知道我是否在正确的轨道上......任何帮助表示赞赏!


提前致谢,

Karen
Hi there,

I''ve been searching the net & the forums here over the last few days for help with my problem & am getting myself really confused.. hoping someone may be able to help me here.

I''ve got a continuous form which has 6 textboxes in each row, one of which contains the name of an Assessor, who (in another table) will have a particular colour assigned for him/her.

What I''m trying to do is loop through the records of the continuous form, get the colour value for the Assessor for that record, & then change the background colour of all textboxes in that record to that colour. (I hope that makes sense)

I''ve been messing around trying to do this with Recordset clones, then trying Me.Controls instead.. but so far no luck. (I am very foggy on whether I should be using a Recordset or directly working with the controls on the form..?)

Here''s what I''ve got at the moment (but I keep changing it, so this is kinda muddled):

Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim lngColour As Long
Dim ctl As Control

Set rs = Me.RecordsetClone
rs.MoveFirst

Do While Not rs.EOF

If Not IsNull(rs.Fields("AssessorName")) Then

lngColour = DLookup("[AssessorColour]", "Assessors", "[AssessorName]=''" & rs.Fields("AssessorName").Value & "''")

'' the following doesn''t work...
''
For Each fld In rs.Fields
fld.Properties("BackColor").Value = lngColor
Next

'' following doesn''t work either -- it changes all textboxes on
'' the whole form to lngColour! (permanently, for some weird reason?!)
'' How do I just loop through the controls in 1 record?
''
'' For Each ctl In Me.Controls
'' If ctl.ControlType = acTextBox Then
'' ctl.BackColor = lngColour
'' End If
'' Next ctl

End If

rs.MoveNext

Loop

So there are 2 kinda separate ideas there, neither right, & I really don''t know if I''m even on the right track.. any help appreciated!

Thanks in advance,
Karen



您可以在Form的OnCurrent()事件中执行您的请求但仅适用于当前记录。

You can do what you request in the OnCurrent() Event of the Form but only for the Current Record.


感谢大家你的回复玛丽& ADezii!我希望这不是答案,因为......必须找出一种不同的方法来实现这一目标...... arrgh!


将调查条件格式,谢谢你小费,玛丽。


不幸的是,ADezii我需要为所有记录而不仅仅是当前记录,以便用户可以通过扫描列表快速查看哪些记录需要X动作(来自一种颜色),哪些记录需要Y动作(来自另一种颜色),......等等。


显然,过滤表单只显示一种特定类型的记录时间可以解决问题,但是客户习惯于使用电子表格,在电子表格中,他们适当地对相关行进行着色,&他们希望继续能够做到这一点。


任何更多的提示赞赏 - 但无论如何,谢谢你的回复,非常感谢他们,让我浪费了更多的时间在代码上! :)


再次感谢,

Karen
Thanks heaps for your replies Mary & ADezii! I was hoping that wouldn''t be the answer, tho.. will have to figure out a different way to achieve this.. arrgh!

Will investigate Conditional Formatting, thanks for the tip, Mary.

Unfortunately ADezii I need to do it for all records, not just the current record, so that the user can quickly see - by scanning the list - which records need X action (from one colour), which records need Y action (from another colour), ... etc.

Obviously, filtering the form to only show one particular type of record at a time would do the trick, however the client is used to using a spreadsheet in which they coloured the relevant lines appropriately, & they want to continue being able to do that.

Any more tips appreciated -- but thanks heaps for your responses anyway, really appreciate them, saved me wasting any more time on that code! :)

Thanks again,
Karen


这篇关于以连续形式更改不同记录的bg颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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