Solved

Autoselecting the First item in a combo-box

Posted on 1998-08-05
5
147 Views
Last Modified: 2010-04-30
I am sure this has been answered before, but I don't feel like searching through 5000 questions.  How do you autoselect the first item in a drop-down combo box.  I have added all of the items in there, but I want the first item to be pre-selected.
0
Comment
Question by:dt19643063098
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 50 total points
ID: 1467986
Combo1.ListIndex = 0
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467987
Now that I've locked in the answer, to avoid errors in case the list is empty, you should use this code:
If Combo1.ListCount > 0 Then
  Combo1.ListIndex = 0
Else
  Combo1.ListIndex = -1
End If
0
 

Author Comment

by:dt19643063098
ID: 1467988
That doesn't allow me to select anything, it autoselects it and then invokes the click event.  I mis-worded the question.  I want the first item to appear, but not be pre-selected.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467989
Oh, in that case:
Combo1.Text = Combo1.List(0)
(use the error avoiding code above)

0
 

Author Comment

by:dt19643063098
ID: 1467990
Thanks for the help.  If your familiar with Crystal Reports, you might want to look at the other question I submitted.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question