VBA:对ME的通用引用 [英] VBA: Generic reference to ME

查看:584
本文介绍了VBA:对ME的通用引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


我想更改字段的背景颜色,因为它们是输入进行编辑的
。 (然后,当然,在退出时更改它们)


我的原型包括使用几个名为

EditColor和NormalColor的全局CONST。


我的事件代码如下:


Private Sub LastName_Enter()

Me!LastName.BackColor = EditColor

结束子


Private Sub LastName_Exit(取消为整数)

Me!LastName.BackColor = NormalColor

结束子


虽然这给了我正在寻找的效果,但似乎有
必须是一种更有效的方法来做到这一点。我认为我应该能够在代码模块中创建两个子程序,可以从所有字段事件(Enter和Exit)调用

并传递引用

当前字段。


我会称它们为ColorMeEdit和ColorMeNormal。


然后在现场输入事件,你只需要调用那个subrountine。

如果没别的话,这会大大减少打字的数量。


但是,我不知道如何通过

子程序的引用(到当前字段)。


有人能告诉我这样做的代码吗?


谢谢!

Greetings,

I would like to change the background color of fields as they are
entered for editing. (then, of course, change them back on exit)

My prototype consists of using a couple of global CONST called
EditColor and NormalColor.

I have event code as follows:

Private Sub LastName_Enter()
Me!LastName.BackColor = EditColor
End Sub

Private Sub LastName_Exit(Cancel as Integer)
Me!LastName.BackColor = NormalColor
End Sub

While this gives me the effect that Im looking for, it seems like there
has to be a more efficient way to do this. Im thinking that I should
be able to create two subroutines in a code module that can be called
from all the field events (Enter and Exit) and passing a reference to
the current field.

I would call them ColorMeEdit and ColorMeNormal for instance.

Then in the field Enter event, you would just call that subrountine.
That would dramtically reduce the amount of typing if nothing else.

But, I dont know how to pass a reference (to the current field) to the
subroutine.

Could someone show me code that would do this?

Thanks!

推荐答案

最简单的方法是使用confitional formating来改变

控件具有焦点时的背景。


但是如果您更喜欢全局子程序,那么您可以执行以下操作:


Public sub ColorMeEdit()

使用CodeContex tObject

.ActiveControl.BackColor = EditColor

结束

结束子

The easiest way is to use confitional formating to change the
background when the control has focus.

But if you prefer a global subroutine then you can do something like:

Public sub ColorMeEdit()
With CodeContextObject
.ActiveControl.BackColor = EditColor
End With
End sub


非常酷。这正是我需要知道的。两个建议

都是正确的目标,我很高兴你指出有条件的

格式。唯一的问题是我无法获得我想要的颜色

。令人惊讶的是,您只能访问

基本颜色。 (也许是因为界面偏好我不知道。)


无论如何,我正在运行。再次感谢!

Very cool. This is just what I was needing to know. Both suggestions
were right on target, and Im glad you pointed out the Conditional
Formatting. The only problem with this is that I cant get to the color
that Im wanting. It''s suprising that you are only able to access the
basic colors. (Perhaps it is due to an interface preference that Im
not aware of.)

Anyway, Im off and running. Thanks again!


没问题。您还可以将表单的引用传递给

子例程。


Public sub ColorMe(frm as Form)

frm .ActiveControl.BackColor =颜色

结束子


调用它:调用ColorMeEdit(Me)

No problem. You could also pass a reference of the form to the
subroutine.

Public sub ColorMe(frm as Form)
frm.ActiveControl.BackColor = Color
End sub

Call it with: Call ColorMeEdit(Me)


这篇关于VBA:对ME的通用引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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