Results 1 to 3 of 3
  1. #1
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78

    MS Access to Excel SaveAs Dialog Trapped Behind Application Non-Responsive...

    I have a report that dumps a query into Excel and then I format it with some code.... Trying to prompt the user to save the report. However, sometimes the dialog gets trapped and you can't get to it. Is there a way to force the SaveAs Dialog to the front using a windows API or something? OR should I just kill the SaveAs portion.



    This has happened to me before at another company...so it isn't just a one off.


    Code:
    Sub ExportToTemplate()
    
    
        Dim rng               As Range
        Dim xl                As Excel.Application
        Dim xlWS              As Worksheet
        Dim xlFilePath        As String
        Dim xlSaveAsPath      As Variant
        Dim qdf               As QueryDef
        Dim db                As DAO.Database
        Dim rst               As DAO.Recordset
    
        On Error GoTo ErrHandler
        Set xl = New Excel.Application
        Set db = CurrentDb()
        
        'Define File String Variables
        xlFilePath = "\\ns-linyvfs02\CDT_Reporting_v1.xlsx" ' The template file to dump data into....
        
        xlSaveAsPath = xl.GetSaveAsFilename(FileFilter:= _
        "Excel Files (*.xlsx), *.xlsx, Macro Enabled Workbook" & _
        "(*.xlsm), *xlsm", Title:=strTitle, _
        InitialFileName:="C:\Users\" & Environ("username") & "\Desktop\" & "CDT_Report_" & Format(Date, "MM_DD_YYYY"))
        If xlSaveAsPath = False Then
            MsgBox "Report Creation has been aborted!", vbCritical, strTitle
            Exit Sub
        End If
        
        With xl
            .Workbooks.Open xlFilePath 'Open Template Workbook
            Set xlWS = .Sheets("Overview")
        End With
        
        With xlWS
            Set qdf = db.QueryDefs("qryRptMonitoring") 'Set Query Definition
            Set rst = qdf.OpenRecordset 'Open Recordset
            Set rng = .Range("A1") 'Define range for export
            rng.Offset(2, 0).CopyFromRecordset rst 'Copy RecordSet to Worksheet
            rst.Close 'Close RecordSet
    
    
           'Format Workbook code here....not relevant
                                                             
        End With    
                                 
        xl.ActiveWorkbook.SaveAs xlSaveAsPath 'Save the file <-----This dialog gets stuck behind other applications
        xl.Visible = True 'Make Workbook Visible
        Exit Sub
    
    
    ErrHandler:
        MsgBox "An error has occured.  Please contact file administarator.", vbInformation, strTitle
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    Before the saveAs, minimize Access,
    Docmd.minimize
    sAveAs

  3. #3
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78
    Thanks. Looks to be working! Appreciate the help.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-15-2015, 05:50 AM
  2. Access Opens Excel, Edit, SaveAs, then Close
    By jadown in forum Programming
    Replies: 6
    Last Post: 03-09-2015, 09:50 AM
  3. Saveas Dialog Box With .xlsx As Filetype
    By Manish_05 in forum Import/Export Data
    Replies: 7
    Last Post: 05-07-2014, 12:16 PM
  4. Replies: 5
    Last Post: 07-22-2013, 01:11 PM
  5. Open a specific Excel application in Access
    By Hobbes29 in forum Programming
    Replies: 1
    Last Post: 02-14-2011, 06:48 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