Displaying field's description in label or textbox on form

Deadly 提交于 2019-12-31 03:53:04

问题


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

How do I access the text in the status bar (the field description) in VBA?


回答1:


The text in the status bar is the current field's Description property.

From VBA, you can access the Description of a field in the form's recordset.

Debug.Print Me.Recordset.fields("id").Properties("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")

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.

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.

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.



来源:https://stackoverflow.com/questions/12939843/displaying-fields-description-in-label-or-textbox-on-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!