Results 1 to 4 of 4
  1. #1
    trident is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    141

    Button to export using DoCMD

    I have created a report that I am going to export to excel. In a form i prepared a button for this, and the button is ON CLICK, below is the command i copied from the net:



    Sub export_report_to_excel()
    Dim rptname As String
    rptname = "dt2 export"
    DoCmd.OutputTo acOutputReport, "dt2 export", acFormatXLS, "C:\LIBRARIRES\DOCUMENT\DT2eXPORT.XLS", True

    End Sub

    My problem is that when I save the same, and click the button, nothing happens, when I return to the design view, the ON CLICK is blank and when I open the code, it always brings me to the below blank code:


    Private Sub Command22_Click()


    End Sub

    Can you please assist me on this small project.

    thank you.

    Trident

  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    You don't say where you are initiating this from - property sheet or vb editor. It's been my experience that sometimes if I choose the object and event while in the vb editor, then write code for it, the connection does not seem to be made to the form object - even if [Event Procedure] is showing on the property sheet after doing so. The 'connection' I refer to means the event would not run until I clicked the builder button on the property sheet event line. This took me to the code I had written - and the event would run thereafter. So, I'm saying it's best to create all events associated with db objects by using the property sheet to begin with. Not sure if this is a bug that creeps in after a lot of design changes and no compact/repair ever having been done or what.

    However, it does not explain why your written code is missing. For that, I can't think of what it could be besides you not saving your changes? Two similar procedures, one not 'connected'?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Maybe this would work:

    Code:
    Private Sub Command22_Click()
        Call export_report_to_excel
    End Sub

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Guess I misunderstood. I thought you had put that code in your own sub.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-21-2014, 02:29 PM
  2. DoCmd to Export?
    By aellistechsupport in forum Modules
    Replies: 20
    Last Post: 04-29-2014, 12:57 PM
  3. Export specifications with DoCmd.OutputTo acOutputQuery
    By Mattbro in forum Import/Export Data
    Replies: 2
    Last Post: 03-21-2014, 08:17 AM
  4. Replies: 4
    Last Post: 02-12-2014, 12:49 PM
  5. Export to Text File Using DoCmd Access 2007
    By tonere in forum Programming
    Replies: 1
    Last Post: 03-30-2011, 06:14 PM

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