问题描述
我想做的是在表单上的标签中显示当前选定字段的描述.我觉得它当前显示的位置(状态栏的左下角)几乎不明显.
What I'd like to do is display the description from the currently selected field in a label on my form. I feel that where it is currently being displayed (the bottom left status bar) is barely noticeable.
如何在状态栏中访问该值?例如,在我的表单上,当我选择了雇员姓名"字段时,在小字体的左下方,它显示您正在注册的雇员姓名".
How do I access that value in the status bar? For example, on my form, when I have a say, employee name field selected, in the bottom left in small print, it displays "The name of the employee you are registering."
我知道在窗体上的某些情况下,我需要执行此操作的代码
I know in some event on my form, I need code that does
me.lblControlDescription.Caption = me.statusbar.caption
如何在VBA中访问状态栏中的文本(字段说明)?
How do I access the text in the status bar (the field description) in VBA?
推荐答案
状态栏中的文本是当前字段的Description
属性.
The text in the status bar is the current field's Description
property.
从VBA,您可以访问表单记录集中的字段的Description
.
From VBA, you can access the Description
of a field in the form's recordset.
Debug.Print Me.Recordset.fields("id").Properties("Description")
因此,如果您有一个名为lblDescription
的标签控件,则可以将其.Caption
值设置为该字段的Description
.
So, if you have a label control named lblDescription
, you can set its .Caption
value to the field's Description
.
Me.lblDescription.Caption = Me.Recordset.fields("id").Properties("Description")
但是,这可能更加复杂. Description
是用户创建的属性,这意味着它只有在您赋予它一个值后才存在.而且,如果您有一套,但是以后又删除了它的值,那么该属性本身将不再存在.
However, this could be more complicated. Description
is a user-created property, which means that it doesn't exist until you give it a value. And, if you have one set, but delete its value later, the property itself no longer exists.
如果在不存在的情况下尝试检索Description
,则VBA将引发错误#3270,找不到属性".您可以捕获该错误,并在发生错误时将Me.lblDescription.Caption
设置为vbNullString
.
If you attempt to retrieve the Description
when one doesn't exist, VBA will throw error #3270, "Property not found." You could trap that error, and set Me.lblDescription.Caption
to vbNullString
when it happens.
您还需要一种策略,用于何时更改Me.lblDescription.Caption
.您可以创建一个过程以根据当前活动控件进行设置.然后从窗体的每个控件的on focus事件中调用该过程.也许有更好的方法,但是我暂时还没有看到.
You also need a strategy for when to change Me.lblDescription.Caption
. You could create a procedure to set it based on the current active control. Then call that procedure from the on focus event of each of your form's controls. There may be a better approach for this, but I'm not seeing one just now.
这篇关于在表单上的标签或文本框中显示字段的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!