Field Caption

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to get and set the caption property of a field in a
table, using vba?
 
=?Utf-8?B?RGVubmlzR3VpbGJhdWx0?=
Does anyone know how to get and set the caption property of a field in
a table, using vba?

Look up help for the Properties collection of the DAO.Field object.
IIRC, it's one of those custom properties that doesn't exist until it's
set, so you have to test for its existence before trying to read it or
set it.

In any case, there is no logical reason for doing this programatically.

If you or your users have access to the Access GUI, then you can set it
there using the Table Design window, with a great deal less fuss.

If you or your users do not have access to the Access GUI, then there is
no plausible use for the Caption property, because its only job in life
if to provide a default caption for the label associated with controls
you drop onto a new form. No GUI means no forms or report creation, so
no use for the Caption property.

All the best


Tim F
 
Actually, the "plausable" reason for doing this is just for my benefit.

I have the verbiage I want in the Description property, but I want to put
that verbiabe in the Caption so that when I creat forms for each of my
tables, I automatically get the verbiage for the text controls labels.

I just want to write a quick utility to do this for me.
 
DennisGuilbault said:
Does anyone know how to get and set the caption property of a field in a
table, using vba?

Dennis,

I was also looking to find out whether or not it was possible to set the
caption of the field in a table using VBA. Using Tim's response, even though
I didn't appreciate him lecturing about how "there was no logical reason for
doing this", I was able to get it done.

Try this code...

Sub FieldX()

Dim dbs As Database
Dim fld As Field
Dim prpCaption As Property

Set dbs = CurrentDb
Set fld = dbs.TableDefs("your_table").Fields("field_name")
Set prpCaption = fld.CreateProperty("Caption", dbText, "your_text_here")

On Error Resume Next
fld.Properties.Append prpCaption
dbs.Close

End Sub

Hope this helps you out.

Dave
 
Back
Top