Change the
cmbLocation.Text" 'part to cmbLocation.Index 'and the index number
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
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
PoisonedHeart
Junior Poster in Training
57 posts since Jul 2009
Reputation Points: 14
Solved Threads: 14
It was a pleasure. Please mark this as solved, thanks.:)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350