How do I create a combo box to display the caption for the fields of the form source table ?

Falcon88

Registered User.
Local time
Today, 18:05
Joined
Nov 4, 2014
Messages
309
Hii all dears
How How do I create a combo box to display the caption for the fields of the form source table ?
 
Maybe there is an easier way
The issue is that the Caption is a property of a table or query def. But it is a user defined property, which means it does not exist in the properties collection until you define it. So if you try to check the Caption property you will get an error on any field without a caption.


Code:
Me.Combo12.RowSource = GetCaptions("categories", dt_tableDef)


Code:
Public Enum DefType
  dt_tableDef = 1
  dt_queryDef = 2
End Enum

Public Function GetCaptions(Domain As String, TheDefType As DefType) As String
  Dim fld As DAO.Field
  Dim def As Object
  Dim db As DAO.Database
  Set db = CurrentDb
  Select Case TheDefType
    Case dt_tableDef
         Set def = db.TableDefs(Domain)
    Case dt_queryDef
       Set def = db.QueryDefs(Domain)
  End Select
  For Each fld In def.Fields
    If GetCaptions = "" Then
      GetCaptions = GetCaption(fld)
    Else
      GetCaptions = GetCaptions & ";" & GetCaption(fld)
    End If
  Next fld
End Function
Public Function GetCaption(fld As DAO.Field)
   On Error GoTo errlbl
  GetCaption = fld.Name
  GetCaption = fld.Properties("caption")
 
  Exit Function
errlbl:
  If Err.Number <> 3270 Then Debug.Print Err.Number & " " & Err.Description
End Function
 
Are you talking about the Column Heads property on the Format tab of the list/combo
 
Hii all dears
How How do I create a combo box to display the caption for the fields of the form source table ?
Some say using the Caption property can cause confusion when writing code, and it's recommended to use an Alias instead.
 

Users who are viewing this thread

Back
Top Bottom