Save with Pop-up window when exporting a XML file with VBA (1 Viewer)

Tea

Member
Local time
Today, 15:08
Joined
Oct 30, 2020
Messages
43
Hello, I would like to export a XML file, on click event via button. When it exports I would like to show a pop up window, where to save the file to. Same when you want to save a file a picture online, it's shows you the file explorer. Is it possible with the ExportXML method?

Here is how my code looks like

Code:
Dim contacts As AdditionalData
Dim filter As String

Set contacts = Application.CreateAdditionalData

contacts .Add "tbl_xm_ct"

filter = Me.ID

Application.ExportXML ObjectType:=acExportTable, DataSource:="tbl_xm", _
DataTarget:="C:\Users\...\test.xml", _
WhereCondition:="ID=" & filter, _
AdditionalData:=contacts

It just saves to DataTarget when it's defined, but I don't want to set where it should save to, but so can the user choose himself where to save it.

Thank you!!
 

bastanu

AWF VIP
Local time
Today, 06:08
Joined
Apr 13, 2010
Messages
1,207

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:08
Joined
Feb 19, 2002
Messages
36,889
Don't use a popup dialog to prompt for a target location. Add a control to the form so you can do what @bastanu recommended and use the Windows dialog. If you insist on a popup, make your own form so you can use the Windows dialog.
 

Tea

Member
Local time
Today, 15:08
Joined
Oct 30, 2020
Messages
43
Use the built in FileDialog to do that:

Cheers,
The msoFileDialogOpen and msoFileDialogSaveAs constants are not supported in Microsoft Access.
Is there some built in like this for access ? Thank you!
 

bastanu

AWF VIP
Local time
Today, 06:08
Joined
Apr 13, 2010
Messages
1,207
If you look in the same thread where you found that (https://www.access-programmers.co.uk/forums/threads/save-as-dialog-box.270344/) and check post #3 you will find the solution:
Code:
Sub TestFileDialog()
Dim strFilename As String
 With Application.FileDialog(msoFileDialogSaveAs)
   If .Show Then
   strFilename = .SelectedItems(1)
  Else
    MsgBox "No filename specified!", vbExclamation
Exit Sub
End If
End With
' Do something dreadful with strFilename
...
End Sub
 

Users who are viewing this thread

Top Bottom