Caption change on table

G

gg

I would like to change the captions of some table fields based on other
criteria. I can change captions easily on forms and reports, but would like
to do it on the table. Is it possible to do it with code?
 
K

KC-Mass

It is possible.
Look for references to the DDL (data definition language) component in SQL.
I believe that to rename a column you would need to ALTER TABLE tblName ADD
a column; move data into it from the existing column with an UPDATE query
and then ALTER TABLE tblName DROP the old column.

Some simple info here: http://support.microsoft.com/kb/180841

Regards

Kevin
 
K

KC-Mass

I may have misread your question. Do you want to rename the Columns/fields
or just the labels?
 
E

egerds

Assuming function is in same accdbs, and only one field needs to be
updated

Private Function Update_Field_Caption(str_tblname As String,
str_fldname As String, str_newcaption As String)
CurrentDb().TableDefs(str_tblname).Fields(str_fldname).Properties
("Caption").value = str_newcaption
End Function
 
G

gg

What I am trying to do is, with code, to do the same thing that you do
manually in the design view of a table when you fill in the caption property
for a field name. I think that your reply covers that. I just gave your
reference a quick look, and will study. I am also going to try the next
answer from egerds Thanks.
 
G

gg

Thanks for quick reply. I tried code belowwith a table named 99JS a with a
text field called OldName.

CurrentDb().TableDefs("99JS").Fields("OldName").Properties("Caption").Value
= "NewName"

I get an error message :
Ambiguous Name Detected: Update_Field_Caption

An aside-I have Ac2000 and it won't display help screen for TableDefs. Is
this my machine or another of those things that makes Ac2k infamours?
 
G

gg

I'm a little redfaced-the error I reported (ambigous etc) was caused by my
clutter on the code screen. I got rid of that, but now I get this error:
"Run-time error 3270 Property not found". Any ideas?

The expression I am using is:
CurrentDb().TableDefs("99JS").Fields("OldName").Properties("Caption").Value
= "NewName"

where OldName is a field name in table 99JS
Thanks again.
 
G

gg

I'm a little redfaced-the error I reported (ambigous etc) was caused by my
clutter on the code screen. I got rid of that, but now I get this error:
"Run-time error 3270 Property not found". Any ideas?

The expression I am using is:
CurrentDb().TableDefs("99JS").Fields("OldName").Properties("Caption").Value
= "NewName"

where OldName is a field name in table 99JS
Thanks again.
 
D

davbib

gg said:
What I am trying to do is, with code, to do the same thing that you do
manually in the design view of a table when you fill in the caption property
for a field name. I think that your reply covers that. I just gave your
reference a quick look, and will study. I am also going to try the next
answer from egerds Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top