Displaying field's description in label or textbox on form

前端 未结 1 509
一整个雨季
一整个雨季 2021-01-23 12:30

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 statu

相关标签:
1条回答
  • 2021-01-23 13:20

    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.

    0 讨论(0)
提交回复
热议问题