[RESOLVED] Allow User To Copy File To Folder or Drive
Hi,
I need to be able to allow a user to save a file to their choice of desktop, folder, flash drive etc etc.
They do not need to choose the file to copy, I can hard code this info into the code itself. They just need the abilty to choose where to save it.
Can anyone point me in the right direction please.
Thanks in advance.
Daz.....
Re: Allow User To Copy File To Folder or Drive
Yes use a commondialog to choose a file and then use the common dialog to save the file as well...
Edit
Here is an Example
Create a form, Add a label, Common Dialog, and two buttons to it. The First button is for file select and the second button is to save the file...
Code:
Private Sub Command1_Click()
On Error GoTo errhandler
CommonDialog1.CancelError = True
'~~> Set flags
CommonDialog1.flags = cdlOFNHideReadOnly + cdlOFNPathMustExist + cdlOFNFileMustExist
'~~> Set filters
CommonDialog1.Filter = "All Files (*.*)|*.*"
'~~> Display the Open dialog box
CommonDialog1.FileName = ""
CommonDialog1.ShowOpen
'~~> Store the path in label
Label1.Caption = CommonDialog1.FileName
Command2.Enabled = True
Exit Sub
errhandler:
Select Case Err
Case 32755 '~~> Dialog Cancelled
MsgBox "you cancelled the dialog box"
Case Else
MsgBox "Unexpected error. Err " & Err & " : " & Error
End Select
End Sub
Private Sub Command2_Click()
On Error GoTo errhandler
CommonDialog1.CancelError = True
'~~> Set filters based on the extention of the file chosen
Extn = Right(Label1.Caption, 3)
CommonDialog1.Filter = "*." & Extn & "|*." & Extn
'~~> Display the Save dialog box
CommonDialog1.FileName = Label1.Caption
CommonDialog1.ShowSave
'~~ Save the file
FileCopy Label1.Caption, CommonDialog1.FileName
Exit Sub
errhandler:
Select Case Err
Case 32755 '~~> Dialog Cancelled
MsgBox "you cancelled the dialog box"
Case Else
MsgBox "Unexpected error. Err " & Err & " : " & Error
End Select
End Sub