Use VBA to loop through combo box list and run MS Access macro for each

Weasy picture Weasy · Mar 29, 2011 · Viewed 15.3k times · Source

Currently I have an MS Access 2003 form with a combo box list of names. The way to use this tool: You select a name from the drop down and then click the MS Access Macro which runs (3 different queries) based upon name selected and then you open a master Excel Template and run an Excel Macro which will create 1 individual file for each salesperson.

What I am trying to do: Use MS Access VBA code to loop though the list of names in the combo box and then run the existing MS Access Macro to run each query from the list of names indiividually and then export each sales persons data to an excel Template which is already formatted or just to an Excel file and I will format.

I dont want to manually select a each name, a total of over 300 names from the drop down, it takes too long to run all of these queries. I want to use VBA code to loop through each name in the combo box on the form and use each name to run the existing ms access macro (which runs 3 queries together) and then I want to have the function export each individual file to Excel. The end result is that each salesperson will have his own Excel file.

Answer

Patrick Honorez picture Patrick Honorez · Mar 5, 2012
Dim i As Long
  with myCombo
    For i = 0 To .ListCount
        Debug.Print .ItemData(i)
    Next i
end with