VB6 fill a ListBox

Posted on 2011-10-27
Last Modified: 2012-05-12
I cannot figure out why my ListBox won't display the values pulled from my MySQL table.  Table contains 12 rows of data and the select statement works directly in SQL Server.

This routine is called upon form load.
Private Sub fLoadGuiParmList()
    Dim fsCmd As String
    Dim fsName As String
    Call lstGuiParm.Clear
    fsCmd = ""
    fsCmd = fsCmd & "SELECT  * "
    fsCmd = fsCmd & "FROM   GuiParmList "
    fsCmd = fsCmd & "ORDER  BY ParmNm "
    Set goRecSet = goConn.Execute(fsCmd)
    If Not goRecSet.EOF Then
        While Not goRecSet.EOF
            fsName = goRecSet("ParmNm")
            Call lstGuiParm.AddItem(fsName)
    End If
    lstGuiParm.ListIndex = 0
End Sub

Open in new window

Question by:kkbenj
    LVL 69

    Accepted Solution

    I am not sure if I remember correctly but wasn't there something about the kind of recordset opened with Execute?

    Can you try this:

        Set goRecSet = goConn.Execute(fsCmd)
    '    If Not goRecSet.EOF Then
    '        goRecSet.MoveFirst
            While Not goRecSet.EOF
                fsName = goRecSet("ParmNm")
                Call lstGuiParm.AddItem(fsName)
     '   End If

    Author Comment

    emoreau -
    I use this loop elsewhere in my code and it works.  I did try yours anyway and there is no difference.
    LVL 69

    Expert Comment

    by:Éric Moreau
    is there something wrong with your connection object then?

    Author Comment

    no, other loops fill Combo boxes fine.  The difference is this is a list box.
    LVL 16

    Assisted Solution

    Stupid question, but have you tried stepping through the code to prove that there are records to process?

    emoreau is pointing out that when you open a recordset you don't have to use .MoveFirst, the recordset will get initialized pointing to the 1st record.  You only need to use MoveFirst if you need to return to the beginning of the record set.

    Another stupid question.  What sort of value is "ParmNm", or more specific, what is in it.  Is it possible that the "value" of this field is equating to a blank string?

    Author Closing Comment

    HooKooDooKu - no stupid questions where I'm concerned.  I did not step thru the code, but there are values picked up.  It's simply a character field in the db.  BUT immediately after filling the box, a clear command is issued in another setup.  OOPS!

    emoreau - thank you for your explanation of MoveFirst and the correct time to use it.  It's been ages (as you can tell) since I've done VB.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now