Export with a list box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jollywg
    New Member
    • Mar 2008
    • 158

    Export with a list box

    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.

    Code:
    If (lstExport.Selected(1) = vbTrue) Then
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tblSaveMVROutlets", "C:\Maps_MVRs\Append_Work_Files\Analysis\MVRs_Outlets_Export.xls", True
        MsgBox "Exported", vbOKOnly
        End If
    End Sub
    Any help would be greatly appreciated
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    To efficiently process Selected Items in a List Box, use this code as a Template:
    Code:
    Dim varItem As Variant
    
    With Me![lstExport]
      'Make sure at leats 1 Item is selected
      If .ItemsSelected.Count > 0 Then
        For Each varItem In .ItemsSelected
          'Process entry in the Bound Column
          Debug.Print .Column(0, varItem)
        Next
      Else
        Exit Sub
      End If
    End With

    Comment

    Working...