Referencing listbox value in export code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BeachBummin
    New Member
    • Feb 2012
    • 1

    Referencing listbox value in export code

    Hello,

    I have a listbox populated with a series of queries. I am trying to write code so the user selects the query from the list and clicks and export command button.
    Code:
    Private Sub cmdExport_Click()
    Dim strQuerySelect As String
    Dim lstQueryBox As ListBox
    
    strQuerySelect = lstQueryList.Value
    
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, strQuerySelect, "C:\Documents and Settings\RCEA Intern\Desktop\February.xlsx"
    End Sub
    Last edited by NeoPa; Feb 10 '12, 01:43 AM. Reason: Added mandatory [CODE] tags for you
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    You can accomplish this in two Lines of Code, namely:
    Code:
    If IsNull(Me![lstQueryList]) Then Exit Sub
    
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, Me![lstQueryList], _
                              "C:\Documents and Settings\RCEA Intern\Desktop\February.xlsx"

    Comment

    Working...