简体   繁体   中英

MS Access VBA freeze/crash on Export

The lines below are an extract from code used to generate a XML.

Access 2010 freezes then crashes when executing the Set dlgSaveAs line. This seems to only happen when data is imported using .xls files, .csv's seem to work fine.

Don't see what's wrong with the code and why it doesn't work with .xls/.xlsx files.

        Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)

        With dlgSaveAs
            .InitialFileName = strDate & " " & Replace(strTime, ":", "") & " " & strFFI_Filename & " XML Export" & ".xml" 'Set the default filename and directory
            .InitialView = msoFileDialogViewDetails 'Set the default folder view
            .Title = "Please provide a file name" 'Set your own dialog title
        End With

Have you tried doing the following?

With Application.FileDialog(msoFileDialogSaveAs)
        .InitialFileName = strDate & " " & Replace(strTime, ":", "") & " " & strFFI_Filename & " XML Export" & ".xml" 'Set the default filename and directory
        .InitialView = msoFileDialogViewDetails 'Set the default folder view
        .Title = "Please provide a file name" 'Set your own dialog title
End With

Obviously any other code associated with dlgSaveAs would need moving in the With-End With block

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM