?
Solved

Cycling through Combo Box ListItems

Posted on 1999-07-28
6
Medium Priority
?
159 Views
Last Modified: 2010-04-30
I have a combo box on a form. The form is opened up from another form passing in a parameter. The combo box contains that parameter amoung others in the list. How can I make the combo box select or goto that parameter when the form is opened? Example: say the parameter is "trees" so the 2nd form is opened up to the "trees" recordset. The combo box should have "trees" highlighted. Thanks.
0
Comment
Question by:shubbell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
BeedleGuis earned 400 total points
ID: 1528042
Dim inti As Integer
For inti = 0 To Combo1.ListCount
    Combo1.ListIndex = inti
    If UCase(Me.Combo1.Text) = ucase(ParamVal) Then
        Exit For
    End If
Next inti
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1528043
use the code above in the procedure that recieves the parameter you are searching for.  If the form was previousley loaded, make sure to set combo1.listindex =0 before the for loop.
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1528044
disregard that last comment...no need to set it to 0, because it does that in the loop...don't know what I was thinking.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:y2kwacko
ID: 1528045
BeedleGuis, you are correct but you may want to have it go

For inti = 0 to ComboBox.listcount - 1

as the index of the combobox starts from 0 meaning the last item is one less then the combobox's listcount, the same applies for anything else in an array
0
 

Expert Comment

by:EDDYT
ID: 1528046
Try this

combo1 = "trees"
if combo1.listindex = -1 then ' not found
endif
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1528047
I myself wouldn't code it like that. The repeative changes to the ListIndex param will make it flicker.

Try something like this:

target = ucase(trim(target))
'
combo1.listindex = -1  'No item selected as default
'
for ndx = 0 to Combo1.ListCount -1
  if ucase(trim(Combo1.List(ndx))) = Target then
    combo1.ListIndex = ndx
    exit for
  end if
next ndx

This should be functionally equivalent but without the flicker as you go thru a (potentially) long list of items.

M

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

719 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