Results 1 to 8 of 8
  1. #1
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29

    Export withFormatting Macro

    Hello,



    I need help exporting a data that is selected from a listbox. I have already created the listbox and have a button to print only the selected item.
    I want to create a button to export excel data related to listbox. (The listbox contain a city and I want the user to be able to export the list zip code from a table when they click on the button.)

    Thank you,

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Why do you need export to Excel?

    Options:

    1. dynamic parameterized query, export the query object

    2. apply filter criteria to a report, open report, export report
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    I will have to say for with both options. I want to provide the user the ability to select the information they want and when they click on the button it give them an excel with the data from the table. I already have it set to go to report.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    You will have to what?

    Export of report to Excel can give unsatisfactory results - depends how complicated the report is.

    What will user do with the export?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    Sorry I was talking about the option you gave me in your previous reply. I want it to export to excel based on the selection made on the listbox. I want the users to be able to save the data on their computer.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    And that's all they do with it, save it to their computer? Do they actually do anything with the exported data?

    Is this resolved?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    No, It has not been resolved. Yes, I just want to give the user an option to export the data to excel if they choose to. The VB code below is what I'm using for report.I want to be able to do that for Excel Report.

    Private Sub cmdOpenReport_Click()
    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant

    'make sure a selection has been made
    If Me.city.ItemsSelected.Count = 0 Then
    MsgBox " Must select a City"
    Exit Sub
    End If

    'add selected values to string
    Set ctl = Me.city
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & "'" & ctl.ItemData(varItem) & "',"
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)

    'Open the report, restricted to the selected items
    DoCmd.OpenReport "City", acViewReport, , "City IN(" & strWhere & ")"

    Exit_cmdOpenReport_Click:
    End Sub

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Does that much work so far?

    After report is opened:

    DoCmd.OutputTo acOutputReport, "City", acFormatXLS, "C:\somename.xls"
    DoCmd.Close acReport, "City", acSaveNo
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export to Excel Macro
    By NISMOJim in forum Macros
    Replies: 8
    Last Post: 01-23-2014, 09:09 PM
  2. Macro of VBA to Export Report as PDF
    By buck in forum Macros
    Replies: 6
    Last Post: 12-26-2013, 02:44 PM
  3. EXPORT to Excel via Macro
    By ruggierm1 in forum Import/Export Data
    Replies: 15
    Last Post: 09-25-2012, 09:33 AM
  4. Macro export to excel error
    By Andy_d in forum Import/Export Data
    Replies: 7
    Last Post: 04-15-2011, 09:54 AM
  5. Macro to export to excel
    By jlclark4 in forum Import/Export Data
    Replies: 5
    Last Post: 04-15-2011, 08:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums