Hello aLL

I need a small help from you guys..
I am creating project in VB6.0 and access 2003, form has combobox,tab control,textbox msflexgrid .. I am trying to retrive data from database.I have a sub procedure which is nicely working for all controls except combobox.
while debugging I found that when cursor goes to this field cursor exists sub.

cmblocation.text=rsget!location
or 
cmblocation.text=trim(rsget!location)& ""

I dont know where i am going wrong.please help me in this...

thanks in advance

As what I understand, you mean is you're trying to populate the combo box, with data coming from the database,

there are many ways you can load data within a database...

1.) open a recordset object
rs.Open "SELECT * FROM myTable"
2.) then go through the all the records...with a loop

Dim ctr as Integer
Dim i as Integer 
'-> you can make the data type larger than the integer type, like the Double data type if you think that the records could make over a number larger than the integer range..

i = rs.RecordCount
For ctr = 0 to i -1
 Me.Combobox1.AddItem rs(ctr), ctr
 rs.MoveNext
DoEvents '-execute other events, this avoids to make your program to hang up...
Next i

' for me, this code is a lot faster, than using a "Do While rs.EOF<>True" thing...

About the searching for a current item within the combo box, well as you may know, it will depend on the "Style" property of the combo box, if it's style is set to '2' then the "Text" property will be in a read only mode and thus not allowing you to change the selected item,

you can use an API to search within the combo box

Private Const CB_FINDSTRING = &H14C 'declare this to the top of your form module
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
    ByVal lParam As Any) As Long

'then paste this to a sub procedure, preferably on button click or text box change event
    ComboBox1.ListIndex = SendMessage(ComboBox1.hwnd, CB_FINDSTRING, -1, _
        ByVal CStr("YOUR SEARCH STRING HERE!!")) '-> you can replace this string with a textbox control's text property

Edited 6 Years Ago by PoisonedHeart: n/a

This question has already been answered. Start a new discussion instead.