Loop? Iterate?ListBox

dtaylor

Active Member
Joined
Mar 21, 2002
Messages
379
Hello ALL!,
This is my first post in the Access area.

What I want to do is take the contents of a list box and perform actions on each one of its items.

The basis of my project is an export form that will be resusable and userfriendly for some of my associates.

My form contains a
combobox - filled with District Sales Managers

ListBox - Filled with Account Managers associated with District Sales Manager.

Frame containing following:

CmdButton - Param SQL statment that exports query contents based on selection of combobox and listbox. Uses a Select statement that basis the export selection on the selection of the two checkboxes.

2 checkboxes
1st - Exports single selection based on Districe Manager and single Account Manager from ListBox selection. Works no problem.

2nd - CURRENTLY - Exports all items within listbox to one .xls file but all Account Managers in ListBox are exported to one sheet.
What I want to happen is export each Account Manager in the ListBox to its own tab.

If currently I select one Account Manager at a time and export to the same .xls file the result is a tabbed file of each Account Manager.

The code for export and my naming conventions are no problem but How do you select each item in a listbox and run my export code on each item???


I apologize for my request being so long winded!

Thanks

Dan
This message was edited by dtaylor on 2003-01-20 12:19
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
No need to select each item. Just use code like in your single-selection part, but loop through the list box (like you were alluding to). Something like:

<pre>For lngI = 1 to lboMyListBox.ListCount
myVar = lboMyListBox.ItemData(lngI - 1)
strSQL = "something " & myVar & " something else"
' run SQL
Next lngI</pre>

HTH,

Russell
 
Upvote 0

Forum statistics

Threads
1,221,510
Messages
6,160,226
Members
451,632
Latest member
purpleflower26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top