i have a form in VB. iam using SQL Server as Back-end. And connection string and all works properly. the only one thing is i want to retrieve data from database into a combobox. i'am using this code....

[ dim i ]
[ for i = 0 to Combo1.ListCount - 1 ]
[ Combo1.Text = Combo1.AddItem "rst!fieldname1" ]
[ Next ]
' wher rst is the recordset. form this code i can get only one record. actually i want to display the list of records from a particular column.
i also tried
[ dim i ]
[ for i = 0 to Combo1.ListCount - 1 ]
[ Combo1.List(i) = rst!fieldname1 ]
[ Next ]
it also doesnt work.

Recommended Answers

All 4 Replies


Well... Its the other way round..
check this :

Do While Not RST.EOF
    Combo1.AddItem RST!fieldname1
Combo1.ListIndex = 0


Hi Veena,
I tried that VB code. but it is showing error. Actually i write a private function for loading records into textbox. like .

[Private Sub loadcontrols() ]
[Do While Not rst!EOF]
[Combo1.AddItem rst!fieldname1]
[Combo1.ListIndex = 0 ]
[Text2.Text = rst!fieldname2]
[Text3.Text = rst!fieldname3]

Like this i have written, but...it shows ..

[Run-time Error '3021']
[Either BOF or EOF is true or the current record has been deleted. Requested operation requires a current record]

I also tried that code in Combo1_Click,Combo1.Scroll,Combo1.Change. but no effect.
can yu tell me any other idea?

I think No problem until the loop. Problem in

[Text2.Text = rst!fieldname2]
[Text3.Text = rst!fieldname3]

I dont know What reason you have add this code.

Any how again use rst.EOF and rst.BOF

If rst.EOF = False And rst.BOF = False  Then
  [Text2.Text = rst!fieldname2]
  [Text3.Text = rst!fieldname3]
End If

hi, i am also new to vb6. i copied your code above and tried it but i got an error like invalid use of null.

please help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.