Changing a field caption

  • Thread starter Thread starter Guest
  • Start date Start date
Well, a field doesn't have a Caption, it has a Name. Labels have Captions.

Try something like:
tdf.Fields(0).Name = "Feature ID"

HTH,
RD
 
This works for me in Access 2003
Currentdb.TableDefs("Faq1").Fields(2).Properties("Caption")="MyText"

The problem is that the Caption property does not exist until it is created
the first time. When you assign a caption in design view of a table, Access
will create the caption property and populate it with the value you specify.
Once that is done you can change the caption.

If you need to assign the caption to the field via VBA code and haven't
assigned a value to the caption at least one time then you need to create
the property and then set the value of the property. See CreateProperty in
the VBA help and check out the example code.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
This works for me in Access 2003
Currentdb.TableDefs("Faq1").Fields(2).Properties("Caption")="MyText"

The problem is that the Caption property does not exist until it is created
the first time. When you assign a caption in design view of a table, Access
will create the caption property and populate it with the value you specify.
Once that is done you can change the caption.

If you need to assign the caption to the field via VBA code and haven't
assigned a value to the caption at least one time then you need to create
the property and then set the value of the property. See CreateProperty in
the VBA help and check out the example code.

Ah yes, I realized not too long after I posted that I had goofed a bit. In
design view for a table, the fields do indeed have a Caption property. It
doesn't, just as you say, exist unless one has previously assigned a value or
created the property. Mea culpa.

There is something that bugged the heck out of me when I was first learning (and
my gf was belly aching about this just yesterday): in many books and tutorials
the reader is told you "can do this" or you "can do that" but rarely is it
discussed why one would "want" to do something. Maybe I'm being thick (or maybe
it's too early in the morning) but why would one want to create a field Caption
in VBA as opposed to doing it at table design time?

Thanks for any insights,
RD
 
I really don't know why I would want to do this on the fly. Users should
not work directly with tables or queries in almost all cases, but should see
and manipulate the data via forms.

The only advantage I am aware of in using captions is that when you add a
control to a form or report the labels attached to controls will
automatically grab the field caption if one is available and use that as the
label's caption. If one is not available, then they use the field name. I
guess that would help to ensure consistent labeling throughout the
application.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
I was doing it because I wanted everything to be perfect when I exported it
to excel.
I found out later you can use a select query to change all field names
anyway though-- which is the same as changing the caption for me.

SO I guess my question was irrelevant,
thanks for the responses though =)

S
 
Back
Top