Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field captions in a local view

Status
Not open for further replies.

Imaginecorp

IS-IT--Management
Jan 7, 2007
635
US
I know there is a way to do this, I need to "transfer" the field captions from a table to its View. I know I can open the View designer, fields tab- click properties and type in the captions. PIA, Is there a quick way to do this.

Thanks and how is everybody, long time since I have been in here...
 
Sorry; should mention these views (about 50+) are already created otherwise I could do it by creating them in code.
Thanks
 
[ ]
Has been a long time since I saw you here. Unfortunately I don't have the foggiest idea what you are talking about, so all I can do is say, "Welcome back."


mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Hi Imaginecorp,

Are you referring to the Caption property of a field? If so, you can get and set this programmatically, using DBGETPROP() or AFIELDS(), and DBSETPROP().

For each table, call AFIELDS() to get the field names and properties into an array. Then loop through the array. For each row in the array, call DBSETPROP(), passing the field name and the caption, which you can obtain from the 16th column of the array.

I think that should do the trick.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Mike,mmerlinn;

I suppose I could write a program using DBGETPROP() & DBSETPROP() to get the field Caption property from a table and write to the field caption property of the corresponding view...Was hoping for a quick and easy way to do this. Would have been nice if views automatically inherited the captions etc.

Mike: 16th column of Afields() is the comment property {G}

Thanks
 
16th column of Afields() is the comment property

Ah, yest. You're right. Don't know how I missed that.

No matter. Just use DBGETPROP() instead.

I don't know of any automatic way of doing it. But at least the code you write can be completely generic and therefore can be applied to any table.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Do not know if this will help you but, Most large Applications need a System Dictionary for users.

My method of creating the System Dictionary is to open the Database Container and Copy it to a free table. I then add a few columns and populate them and split the table into 3 tables. SYS_TABLES, SYS_FIELDS, SYS_INDEXES. In the SYS_FIELDS there is a cloumn for VIEWS with a Index on it.
A I have a set of functions to get info from the Dictonary. One of them is a INDEXSEEK() on the view name.

A little bit of work to set it up but it helps a lot in the long run.


David W. Grewe Dave
 
Hello Dave, you want me to work!!!! Exactly what I am trying to avoid.

A little background: I wrote a generic field validation routine that loops through every control (field) on a form and based upon certain flags assigned to each control (1 = must enter a value, 2 = up to the user, 0 = do not check), pops up a message box, using the field caption, to tell the user which field has to have a value entered if it has been left blank.

With a table I use DBGETPROP() using the control source to get the field caption. A single Table View is not a problem also, as all views open their source tables, and based upon the view control source I get the caption from its table.

The problem is with a view created using multiple tables. No way to identify which view field belongs to which table. The easiest way would be to open the view in a designer and manually enter the Caption in properties… PIA but I think the only alternative.

Thanks
 
Why don't you

a) make a general message saying input in highlighted fields must be made and render the controls yellow or light red?

b) create controls based on container with label+base control, eg label+textbox, label+combobox etc. and then display the label caption?

Just two ideas in totally different directions.

Bye, Olaf.

 
Imaginecorp,

I gave you a suggestion for looping through the field of the table, using DBGETPROP() to find the caption and DBSETPROP() to set the caption in the view.

It seems to me that would solve your problem. Did you consider using it? Is there any reason that it won't work?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Mike;
I am and have been using DBGETPROP() with tables as well as views created from a single table. These are not a problem...

The problem is with a view created from multiple tables. (see response to Dave above).

I need to explain: Quite a few tables have the same field names. Example: table1.manufacturer, table2.manufacturer etc, etc. When combined within a view they become view1.manufacturer_a,view1.manufacturer_2 etc. DBGETPROP() would not know which field to access.

For ease in coding, have always prefaced fields with their alias, changing the table field names is not an option.

Fortunately our app does not have too many views for multiple tables so its proberbly easier for me to hardcode the field captions into the views.

Olaf:
As the app has been using the captions to point the user, including a Gotfocus(), It would not be consistant to use your first suggestion. We used to use the container approach long time ago, (Major PIA). Thanks though
 
I suggest that you don't allow VFP to rename the fields in the view, but rename them yourself in the View code:

SELECT Table1.Manufacturer as T1Manufacturer, ;
Table2.Manufacturer as T2Manufacturer, ...

You can actually do this in the View Designer in VFP 8 and later.

Tamar
 
Imaginecorp,

Quite a few tables have the same field names

So, you're now saying that it's the field names that you want to transfer. Yet your original question specifically asked about field captions.

The captions are quite distinct from the field names, and there's no problem in different fields having the same caption.

Perhaps you could clarify exactly what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I think he was saying that he can't use the fieldnames in code to identify the original fields. That is, because of the repetition, the view renames the fields, so the field name in the view isn't the same as in the table.

Seems to me, though, that DBGetProp() or CursorGetProp() can handle that, too, using the UpdateName property of the field.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top