Any way to get the Caption text for a field? (1 Viewer)

smagnotta

New member
Local time
Today, 04:47
Joined
Mar 1, 2006
Messages
8
All,

I am trying to get the caption text for a field instead of the raw database name. The raw database name can be extracted using the Fields Collection:

Fields.Item(w).Name

Is there a way to retrieve the caption, as this makes more sense to the user?

For example, instead of the field name "numEmp", I want to retrieve "Number of Employees".

I need this because I am creating a form at runtime (on the fly).

Thanks,
Sal
 

smagnotta

New member
Local time
Today, 04:47
Joined
Mar 1, 2006
Messages
8
It said Method or data member not found

rs.Fields.Item(w).Caption <-- does not exist
 

smagnotta

New member
Local time
Today, 04:47
Joined
Mar 1, 2006
Messages
8
I also tried:

rs.Fields.Item(w).Properties("Caption") and it compiles but

I get a run time error 3265: Item cannot be found in the collection corresponding to the requested name or ordinal.

I'm doing something stupid.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:47
Joined
Feb 28, 2001
Messages
27,321
That ain't the caption, its the DESCRIPTION if it is in the .Fields collection.

Caption is a Forms/Reports property.

Try using the right property name.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:47
Joined
Feb 19, 2002
Messages
43,484
Caption is a property of the fields collection of a tabledef. However, it seems to be an optional property, as is Description so you can't reference it with !. Here's the code from my documenter application:
Code:
                TempSet1!FieldName = fldLoop.Name
                TempSet1!OrdinalPosition = fldLoop.OrdinalPosition
                TempSet1!AllowZeroLength = fldLoop.AllowZeroLength
                TempSet1!DefaultValue = fldLoop.DefaultValue
                TempSet1!Size = fldLoop.Size
                TempSet1!Required = fldLoop.Required
                TempSet1!Type = fldLoop.Type
                TempSet1!ValidationRule = fldLoop.ValidationRule
                TempSet1!Attributes = fldLoop.Attributes
                On Error Resume Next ' the following property is only available when it is not null
                TempSet1!Description = fldLoop.Properties("Description")
                TempSet1!FieldType = GetType(fldLoop.Type)
                TempSet1!Caption = fldLoop.Properties("Caption")
                If fldLoop.Attributes And dbAutoIncrField Then  'performs bitwise operation
                    TempSet1!AutoNum = True
                    TempSet1!Required = True
                Else
                    TempSet1!AutoNum = False
                End If
 

Users who are viewing this thread

Top Bottom