Welcome to SPN

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

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

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. OP
    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. OP
    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
    >>
    >>

    >
    >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page