Results 1 to 5 of 5

Thread: Populating a ListBox

  1. #1

    Thread Starter
    Hyperactive Member Dorothy's Avatar
    Join Date
    Feb 2001
    Posts
    310

    Question Populating a ListBox

    I need a function which retrieves all the datas of a specific
    field and add it to the listbox.?

    This code below returns only the last data of the field :

    Private Sub Cmd_onClick()
    lstname.AddItem GetProdList()
    End Sub

    Public Function GetProdList() As Variant
    Dim list As Variant
    Set rsp = New ADODB.Recordset
    rsp.Open "select * from product", cn, adOpenDynamic, adLockOptimistic
    Do While Not rsp.EOF
    list = rsp(0)
    GetProdList = list
    rsp.MoveNext
    Loop
    End Function

    How do I proceed?
    Note: I need to compulsorily use a function to do this.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try something like
    VB Code:
    1. Private Sub cmdAddDates_Click()
    2. Set rsp = New ADODB.Recordset
    3. rsp.Open "SELECT datefield FROM product", cn, adOpenDynamic, adLockOptimistic
    4.       Do While Not rsp.EOF
    5.            List1.Additem rsp(0)
    6.            rsp.MoveNext
    7.       Loop
    8. End Sub

  3. #3

    Thread Starter
    Hyperactive Member Dorothy's Avatar
    Join Date
    Feb 2001
    Posts
    310

    Unhappy

    But I need to have it in a function and call it recursively.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Why?

  5. #5
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    You mean something like this?
    VB Code:
    1. Private Sub PopulateListBox (lst as ListBox)
    2. Set rsp = New ADODB.Recordset
    3. rsp.Open "SELECT datefield FROM product", cn, adOpenDynamic, adLockOptimistic
    4.       Do While Not rsp.EOF
    5.            lst.Additem rsp("FieldName")
    6.            rsp.MoveNext
    7.       Loop
    8. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width