Solved

How to remove all "captions" from all field properties from all tables in database

Posted on 2016-07-17
11
95 Views
Last Modified: 2016-07-18
How can I use VBA to remove all captions from all field properties from all tables in my database.
I use Access 2010.
0
Comment
Question by:Fritz Paul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 40

Expert Comment

by:als315
ID: 41715045
Try this code:
Public Sub remove_captions()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
On Error Resume Next
For Each tdf In db.TableDefs
    ' ignore system and temporary tables
    If Not (tdf.Name Like "MSys*" Or tdf.Name Like "~*") Then
        For Each fld In tdf.Fields
            If fld.Properties("Caption") <> "" Then
                Debug.Print tdf.Name, fld.Name, fld.Properties("Caption")
                fld.Properties.Delete "Caption"
            End If
        Next
    End If
Next
End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 41715736
Paul,

Can I ask why?  Using the Caption property of the field allows you to give the field a meaningful name which shows up in queries and datasheets without actually changing the name of the field.  It is frequently more useful to display those captions than the actual name of your fields

Dale
0
 

Author Comment

by:Fritz Paul
ID: 41715877
@als315
Thanks that looks super. However when I run the code I get an error. Can you see the problem?
Error message.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:als315
ID: 41715883
Was my code modified? There are no FIndRecord or FindNext in my code.
Open debugger and try to find line with error
0
 

Author Comment

by:Fritz Paul
ID: 41715885
@Dale Fye
Thanks for your interest.
I have often wondered about this issue. Adding these captions cause so much confusion when you try to edit forms and queries.
I paste a simple example below.
To make the connection between the data on a report or form and the table is so much more difficult. And whenever you want to change the caption in a datasheet to a new one or to another language, then you really get entangled, because you are just ignored if you add a caption in the query if there is a caption in the table.
So I just wonder why don't you give the field a descriptive name in the first place?
I try to do that and then I add captions if required in the queries.
In this case I work with a legacy database with many tables and fields. It was well written, but unfortunately the programmer used a lot of captions of which some are the same as the field names and some differ. I have wasted so much time editing this database that I now decided to clean the whole thing.
Do you think I am missing something here?
Illustration of confusion.
0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 41715890
Try this sample. Line with deleting is commented. Run code and check errors
Database15.accdb
0
 

Author Closing Comment

by:Fritz Paul
ID: 41715919
Thanks for that sample.
I missed a reference in my database.
It works perfectly now.
Thanks
0
 
LVL 40

Expert Comment

by:als315
ID: 41715949
You are welcome
0
 
LVL 26

Expert Comment

by:Nick67
ID: 41717517
Do you think I am missing something here?
No, if it is a mess, it is a mess.
So I just wonder why don't you give the field a descriptive name in the first place?
I would hate "The ID for the Plant" as a caption, too.
Captions can be nice, in that when you create a new bound control, the label for the control picks up the caption name -- so for PlantID, a caption like "Plant ID" can be nice.
(spaces in field names are abominations!  But nice in labels)

I don't permit the user to see queries, or datasheets, and in design view, a bound control has the field name in the control, so I don't think I would find captions confusing.

And whenever you want to change the caption in a datasheet to a new one or to another language, then you really get entangled, because you are just ignored if you add a caption in the query if there is a caption in the table.
That isn't phrased well.
I hadn't realized that field aliases would be ignored -- because I generally don't use captions -- but you are right that an attempt to alias a column that has a caption fails.
If I put MyNewName:[SomeField] in a query, I DEFINITELY expect to see the alias MyNewName and not the caption of SomeField.  That would be an absolute pain in the rear.

It turns out you can override the caption inherited from the table by right-clicking the field and choosing Properties|Caption, but I could see why you may not want that.

There is also
fld.Properties("Caption").Inherited
It may be too late now, but you could perhaps have kept the captions intact, but prevented them from propagating  to labels and datasheets in whole or in part.
1
 

Author Comment

by:Fritz Paul
ID: 41717611
Nick67 thanks for your detailed comments.
Regards.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 41717635
It was an interesting question.
When I built my tables, I didn't put captions to very many fields (as of now I have 1595 fields in 163 tables) and had always thought about a UI to do so -- but since most of the work that captioning could have saved me is done, I never have.

But aliasing failures would be dreadfully annoying -- but I guess if you knew about what a caption does to aliasing, then the few times you wanted a  custom column caption may not have outweighed the thousands of labels that had to be reworded.

So, thank you for an interesting question
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question