[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


VB6 fill a ListBox

Posted on 2011-10-27
Medium Priority
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
  • 3
  • 2
LVL 70

Accepted Solution

Éric Moreau earned 1000 total points
ID: 37037725
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

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

Expert Comment

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

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

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

Assisted Solution

HooKooDooKu earned 1000 total points
ID: 37037809
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

ID: 37037868
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.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 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