FileDialog SaveAs Code

  • Thread starter Thread starter akphidelt
  • Start date Start date
A

akphidelt

Howdy fellas. I'm working on a code in access. What I'm trying to do is allow
people to Save a file from their documents and automatically save that file
in to the common drive folder.

Right now, here is my code. This code allows me to get the path of the
selected file, but now I want to be able to save that path to a different
path.

The steps I want are

1) open file dialog
2) double click on the file you want
3) macro automatically saves that file in to a different path

Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim filePath As String
Dim fileName As String

filePath = "C:\Test"
fileName = Me.txtFileName

Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog
.Title = "Select File"
.Filters.Clear
.Filters.Add "All Files", "*.*"

If .Show = True Then
For Each varFile In .SelectedItems
Me.txtPath.Value = varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With

'Right here I want it to save varFile as filePath & fileName

Any help will be greatly appreciated. Thanks!
 
The FileDialog is no good. Although it offers the SaveAs option, it doesn't
work in Access.

The only approach that is really reliable without causing versioning
problems is to use the API call. If you've never used this before, it may
look a bit scary, but it's really just copy'n'paste stuff. Here's the code
to copy:
Call Windows File Open/Save Dialog box
at:
http://www.mvps.org/access/api/api0001.htm
 
Back
Top