Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Query Field Names AND Captions Rowsource for ListBox

Discussion in 'Information Technology' started by Debra Farnham, Jul 28, 2006.

  1. Debra Farnham

    Debra Farnham
    Expand Collapse
    Guest

    Hi All

    Access 2K

    With the help of a post by Terry Kreft, I am able to get the Captions from a
    Query to show up in my listbox as follows:

    I also need the the field names.

    Any help would be GREATLY appreciated.

    Debra

    ******************************************************************
    Function ListCaptions(fld As Control, id As Variant, row As Variant, col As
    _
    Variant, code As Variant) As Variant
    Static strCaptions() As String
    Static intCount As Integer
    Select Case code
    Case acLBInitialize ' Initialize.
    Dim loDb As Database
    Dim loTab As QueryDef
    Dim lofld As Field
    Dim intX As Integer
    Set loDb = CurrentDb
    'Change the table name here
    Set loTab = loDb.QueryDefs("qryFieldsForExport")
    intCount = loTab.Fields.Count - 1
    ReDim strCaptions(intCount)
    On Error Resume Next
    For intX = 0 To intCount
    strCaptions(intX) = loTab.Fields(intX).Properties("Caption")
    If Err > 0 Then
    strCaptions(intX) = loTab.Fields(intX).Name
    Err.Clear
    End If
    Next
    Set loTab = Nothing
    Set loDb = Nothing
    ListCaptions = True
    Case acLBOpen ' Open.
    ListCaptions = Timer ' Unique ID.
    Case acLBGetRowCount ' Get rows.
    ListCaptions = intCount + 1
    Case acLBGetColumnCount ' Get columns.
    ListCaptions = 1
    Case acLBGetColumnWidth ' Get column width.
    ListCaptions = -1 ' Use default width.
    Case acLBGetValue ' Get the data.
    ListCaptions = strCaptions(row)
    End Select
     
  2. Loading...

    Similar Threads Forum Date
    Query about Jhatka Meat by Shooting in Head Sikh Sikhi Sikhism Aug 26, 2011
    Who is a sikh? A non sikh friend's query!! Sikh Sikhi Sikhism Apr 30, 2010
    General Query Hard Talk Sep 4, 2008
    Power of pauri's in Japji Sahib query Sikh Sikhi Sikhism Aug 17, 2006
    Sikhism a query Book Reviews & Editorials Aug 2, 2005

  3. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    The following should do it:


    Function ListCaptions(fld As Control, id As Variant, row As Variant, col As
    _
    Variant, code As Variant) As Variant
    Static strCaptions() As String
    Static intCount As Integer
    Select Case code
    Case acLBInitialize ' Initialize.
    Dim loDb As Database
    Dim loTab As QueryDef
    Dim lofld As Field
    Dim intX As Integer
    Set loDb = CurrentDb
    'Change the table name here
    Set loTab = loDb.QueryDefs("qryFieldsForExport")
    intCount = loTab.Fields.Count - 1
    ReDim strCaptions(1, intCount)
    On Error Resume Next
    For intX = 0 To intCount
    strCaptions(0, intX) = loTab.Fields(intX).Name
    strCaptions(1, intX) = loTab.Fields(intX).Properties("Caption")
    If Err > 0 Then
    strCaptions(1, intX) = " No Caption "
    Err.Clear
    End If
    Next
    Set loTab = Nothing
    Set loDb = Nothing
    ListCaptions = True
    Case acLBOpen ' Open.
    ListCaptions = Timer ' Unique ID.
    Case acLBGetRowCount ' Get rows.
    ListCaptions = intCount + 1
    Case acLBGetColumnCount ' Get columns.
    ListCaptions = 2
    Case acLBGetColumnWidth ' Get column width.
    ListCaptions = -1 ' Use default width.
    Case acLBGetValue ' Get the data.
    ListCaptions = strCaptions(col, row)
    End Select



    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Debra Farnham" <nospam@nospam.com> wrote in message
    news:OprHwyIoGHA.1244@TK2MSFTNGP05.phx.gbl...
    > Hi All
    >
    > Access 2K
    >
    > With the help of a post by Terry Kreft, I am able to get the Captions from

    a
    > Query to show up in my listbox as follows:
    >
    > I also need the the field names.
    >
    > Any help would be GREATLY appreciated.
    >
    > Debra
    >
    > ******************************************************************
    > Function ListCaptions(fld As Control, id As Variant, row As Variant, col

    As
    > _
    > Variant, code As Variant) As Variant
    > Static strCaptions() As String
    > Static intCount As Integer
    > Select Case code
    > Case acLBInitialize ' Initialize.
    > Dim loDb As Database
    > Dim loTab As QueryDef
    > Dim lofld As Field
    > Dim intX As Integer
    > Set loDb = CurrentDb
    > 'Change the table name here
    > Set loTab = loDb.QueryDefs("qryFieldsForExport")
    > intCount = loTab.Fields.Count - 1
    > ReDim strCaptions(intCount)
    > On Error Resume Next
    > For intX = 0 To intCount
    > strCaptions(intX) = loTab.Fields(intX).Properties("Caption")
    > If Err > 0 Then
    > strCaptions(intX) = loTab.Fields(intX).Name
    > Err.Clear
    > End If
    > Next
    > Set loTab = Nothing
    > Set loDb = Nothing
    > ListCaptions = True
    > Case acLBOpen ' Open.
    > ListCaptions = Timer ' Unique ID.
    > Case acLBGetRowCount ' Get rows.
    > ListCaptions = intCount + 1
    > Case acLBGetColumnCount ' Get columns.
    > ListCaptions = 1
    > Case acLBGetColumnWidth ' Get column width.
    > ListCaptions = -1 ' Use default width.
    > Case acLBGetValue ' Get the data.
    > ListCaptions = strCaptions(row)
    > End Select
    >
    >
     
  4. Debra Farnham

    Debra Farnham
    Expand Collapse
    Guest

    Awesome!

    Thanks tons Doug!

    Works like a charm.

    Debra

    "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:%23yD2rmOoGHA.2312@TK2MSFTNGP04.phx.gbl...
    > The following should do it:
    >
    >
    > Function ListCaptions(fld As Control, id As Variant, row As Variant, col
    > As
    > _
    > Variant, code As Variant) As Variant
    > Static strCaptions() As String
    > Static intCount As Integer
    > Select Case code
    > Case acLBInitialize ' Initialize.
    > Dim loDb As Database
    > Dim loTab As QueryDef
    > Dim lofld As Field
    > Dim intX As Integer
    > Set loDb = CurrentDb
    > 'Change the table name here
    > Set loTab = loDb.QueryDefs("qryFieldsForExport")
    > intCount = loTab.Fields.Count - 1
    > ReDim strCaptions(1, intCount)
    > On Error Resume Next
    > For intX = 0 To intCount
    > strCaptions(0, intX) = loTab.Fields(intX).Name
    > strCaptions(1, intX) = loTab.Fields(intX).Properties("Caption")
    > If Err > 0 Then
    > strCaptions(1, intX) = " No Caption "
    > Err.Clear
    > End If
    > Next
    > Set loTab = Nothing
    > Set loDb = Nothing
    > ListCaptions = True
    > Case acLBOpen ' Open.
    > ListCaptions = Timer ' Unique ID.
    > Case acLBGetRowCount ' Get rows.
    > ListCaptions = intCount + 1
    > Case acLBGetColumnCount ' Get columns.
    > ListCaptions = 2
    > Case acLBGetColumnWidth ' Get column width.
    > ListCaptions = -1 ' Use default width.
    > Case acLBGetValue ' Get the data.
    > ListCaptions = strCaptions(col, row)
    > End Select
    >
    >
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "Debra Farnham" <nospam@nospam.com> wrote in message
    > news:OprHwyIoGHA.1244@TK2MSFTNGP05.phx.gbl...
    >> Hi All
    >>
    >> Access 2K
    >>
    >> With the help of a post by Terry Kreft, I am able to get the Captions
    >> from

    > a
    >> Query to show up in my listbox as follows:
    >>
    >> I also need the the field names.
    >>
    >> Any help would be GREATLY appreciated.
    >>
    >> Debra
    >>
    >> ******************************************************************
    >> Function ListCaptions(fld As Control, id As Variant, row As Variant, col

    > As
    >> _
    >> Variant, code As Variant) As Variant
    >> Static strCaptions() As String
    >> Static intCount As Integer
    >> Select Case code
    >> Case acLBInitialize ' Initialize.
    >> Dim loDb As Database
    >> Dim loTab As QueryDef
    >> Dim lofld As Field
    >> Dim intX As Integer
    >> Set loDb = CurrentDb
    >> 'Change the table name here
    >> Set loTab = loDb.QueryDefs("qryFieldsForExport")
    >> intCount = loTab.Fields.Count - 1
    >> ReDim strCaptions(intCount)
    >> On Error Resume Next
    >> For intX = 0 To intCount
    >> strCaptions(intX) = loTab.Fields(intX).Properties("Caption")
    >> If Err > 0 Then
    >> strCaptions(intX) = loTab.Fields(intX).Name
    >> Err.Clear
    >> End If
    >> Next
    >> Set loTab = Nothing
    >> Set loDb = Nothing
    >> ListCaptions = True
    >> Case acLBOpen ' Open.
    >> ListCaptions = Timer ' Unique ID.
    >> Case acLBGetRowCount ' Get rows.
    >> ListCaptions = intCount + 1
    >> Case acLBGetColumnCount ' Get columns.
    >> ListCaptions = 1
    >> Case acLBGetColumnWidth ' Get column width.
    >> ListCaptions = -1 ' Use default width.
    >> Case acLBGetValue ' Get the data.
    >> ListCaptions = strCaptions(row)
    >> End Select
    >>
    >>

    >
    >
     

Share This Page