Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box-Default Value

Status
Not open for further replies.

mans

Programmer
Mar 18, 2000
136
AU
Hello,

I use the code below to display items with a combo box (assume all declarations and assignments are OK):

Do While Not rh.EOF
Combo1.AddItem rh!Name
rh.MoveNext
Loop

How can I get the default value in the combo box above to equal the first value in the rh recordset above. At the moment the combo box is empty until I choose an item from the drop down menu.

Thanks
 
Thank you for your response. I previously tried that statement but is does not work. Any other suggestions ?? or does it have something to do with way I have added the items to the combo box or do I need to make an additional declaration before I use the Combo1.ListIndex = 0 statement.

Thanks
 
I expect then that you have the sorted property set true? In which case listindex = 0 gives the lowest value, which you don't want.

You could search through the list after, when you get a match set the listindex

cFirstValueAdded

for l = 0 to combo1.listcount - 1
if combo1.list(l) = cFirstValueAdded then
combo1.listindex = l
exit for
endif
next l

Looks a bit crude, there must be a better way

Peter Meachem
peter@accuflight.com
 
How about
Do While Not rh.EOF
Combo1.AddItem rh!Name
rh.MoveNext
Loop
rh.movefirst
Combo1.text = rh!Name

David Paulson


 
I pulled the .setfocus from somewhere here in tek-tips.
I am not the originator, but it works great if your
use setfocus before setting the listindex.

Me.cmbBus.SetFocus
cmbBus.ListIndex = 0
 
This works!!

Private Sub Form_Load()
Form1.Adodc1.RecordSource = "SELECT distinct site_name.site_name FROM site_name"
Form1.Adodc1.Refresh
Combo1.AddItem Form1.Adodc1.Recordset!site_name
Me.Combo1.ListIndex = 0
Form1.Adodc1.Recordset.MoveNext
While Not Form1.Adodc1.Recordset.EOF
Combo1.AddItem Form1.Adodc1.Recordset!site_name
Form1.Adodc1.Recordset.MoveNext
If Form1.Adodc1.Recordset.EOF Then
Exit Sub
End If
Wend

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top