We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

automating process using combobox values-using a loop

zachvaldez
zachvaldez asked
on
Medium Priority
439 Views
Last Modified: 2008-03-10
I have a combobox(cboEntry) with 5 entries-A,B,C,D,E.( value list) not table/query
currently everything is manually process. I have to select a value in a combo box then click the command button and it processed accordingly the criteria. However I would like to automate the process. Instead of selecting an item in the combo box and executing using it, I would like to loop throug the values and excute the code behind the click event of the command button. Is that possible? sometthing like

....  For i = 0 To Me.lstMod.ListCount - 1 but in my case it is a combo box....
           call cmdExt_click
     next

Can someone show me the code to get this accomplish?
Im debating whether I will use the call to the cmdExt_click or call the modulles currently inside the command button.
Im also debating whether use a listbox instead of combo box.

thanks in advance!

Comment
Watch Question

CERTIFIED EXPERT

Commented:
Hi zachvaldez,
So it sounds like the combo box has no purpose. You can hold the list in memory.

You need some looping code such as ...

Dim arr(4)
Dim x
arr(0)= "A"
arr(1)="B"
arr(2)="C"
arr(3)="D"
arr(4)="E"

For x = 0 to 4
' do something using arr(x)
next x

Pete

Author

Commented:
well,  the combo box or listbox is needed to display what is going on.. although it is automated

Commented:
Dim ctl as combobox
Dim intIndex as integer

 Set ctl = Me!YourComboBox
' Loop through all combo box rows; run your process passing the current combobox value as a parameter
For intIndex = 0 To ctl.ListCount - 1
      YourFunction(ctl.ItemData(intIndex))
Next

Author

Commented:
I was wondering how the function would look like.


 YourFunction(ctl.ItemData(intIndex))>>>

should I say Myfunction(ctlm as combo box , i as integer)

is this right?
Commented:
Since your combobox entries are text the function would look like this:

YourFunction(strComboBoxValue as String)

You are only passing the value in the combobox to your function (or procedure). This line of code: ctl.ItemData(intIndex)), retrieves the value of the combobox on a particular row.  So your function just needs to have a parameter that accepts the value from the combobox.

The whole thing might look like this:

Sub CommandButton1_Click

    Dim ctl as combobox
    Dim intIndex as integer

    Set ctl = Me!YourComboBox
    'Loop through all combo box rows; run your process passing the current combobox value as a parameter
    For intIndex = 0 To ctl.ListCount - 1
        YourFunction(ctl.ItemData(intIndex))
   Next

End Sub

Function YourFunction(strComboBoxValue as String)
   <<<<  Your process >>>>
End Function




Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
In form load..
I would like the combo bx to default to the first value list..
how is that done?

Commented:
Here is how you can select the first item:

Me.YourComboBox = Me.YourComboBox.ItemData(0)


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.