Connecting Tech Pros Worldwide Forums | Help | Site Map

Export with a list box

Member
 
Join Date: Mar 2008
Posts: 114
#1: Aug 19 '08
I'm trying to figure out how to export based on a list box. here is the code that i have, and for some reason its not working.

Expand|Select|Wrap|Line Numbers
  1. If (lstExport.Selected(1) = vbTrue) Then
  2.     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tblSaveMVROutlets", "C:\Maps_MVRs\Append_Work_Files\Analysis\MVRs_Outlets_Export.xls", True
  3.     MsgBox "Exported", vbOKOnly
  4.     End If
  5. End Sub
Any help would be greatly appreciated
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#2: Aug 20 '08

re: Export with a list box


To efficiently process Selected Items in a List Box, use this code as a Template:
Expand|Select|Wrap|Line Numbers
  1. Dim varItem As Variant
  2.  
  3. With Me![lstExport]
  4.   'Make sure at leats 1 Item is selected
  5.   If .ItemsSelected.Count > 0 Then
  6.     For Each varItem In .ItemsSelected
  7.       'Process entry in the Bound Column
  8.       Debug.Print .Column(0, varItem)
  9.     Next
  10.   Else
  11.     Exit Sub
  12.   End If
  13. End With
Reply