We help IT Professionals succeed at work.
Get Started

VB6 - Use recordset to populate dropdown

lakhi asked
Last Modified: 2013-12-26
I have an application that I'm adding another form to and in the process, I stumbled across code that worked at one time and now does not. Grrrr...
I'm selecting usernames from a table and using them (or trying to use them)  to populate a ComboBox(the style is set to 2 Dropdown List). Every time I run the code, the reordcount is -1
If I take the same query and run it against the actual table, the records are there.
What am I doing wrong? I can pull data from the database in other areas of the application.
I even tried breaking out the code into a standalone with just the dropdown and still the recordcount is -1
I'm posting my code. I'm connecting to an Oracle database and the connection is already open.
thanks in advance for help
Public Sub Set_Prod_Control_Values()
  Dim i As Integer
  Dim strSQL As String  
  Dim strCat As String
  strCat = "PC"

  Dim rsPC As ADODB.Recordset
  Set rsPC = New ADODB.Recordset
  strSQL = "Select * from USERS WHERE Category = '~'"
  strSQL = Replace(strSQL, "~", strCat)
  rsPC.Open strSQL, gDC, adOpenForwardOnly, adLockReadOnly, adCmdText
  If Not rsPC.EOF Then
    Me.cboProdControl.AddItem "Select Name"
    For i = 1 To rsPC.RecordCount-1
      Me.cboProdControl.AddItem (rsPC.Fields!User_Name), i
    Next i
  End If

  Set rsPC = Nothing
End Sub

Open in new window

Watch Question
Software Engineer
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE