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

Tea

Member
Local time
Today, 13:09
Joined
Oct 30, 2020
Messages
51
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, 05:09
Joined
Apr 13, 2010
Messages
1,401

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:09
Joined
Feb 19, 2002
Messages
42,970
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, 13:09
Joined
Oct 30, 2020
Messages
51
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, 05:09
Joined
Apr 13, 2010
Messages
1,401
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
 

Sharkbyte

New member
Local time
Today, 08:09
Joined
Jan 5, 2023
Messages
3
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
I get a Method 'FileDialog' of object '_Application' failed message. Any ideas?

Thanks
 

ebs17

Well-known member
Local time
Today, 13:09
Joined
Feb 7, 2020
Messages
1,880
You need a reference to Microsoft Office XX.0 Object Library.
msoFileDialogSaveAs is a constant from this library.

Alternatively, you can use late binding: Late Binding the FileDialog
 

Sharkbyte

New member
Local time
Today, 08:09
Joined
Jan 5, 2023
Messages
3
You need a reference to Microsoft Office XX.0 Object Library.
msoFileDialogSaveAs is a constant from this library.
Thanks. The reference appeared to be in place, but it still showed as not included... Added, and we're up-and-running. Again, appreciate the assist.
 

Users who are viewing this thread

Top Bottom