MS Access - VBA - Take file name from Source to Destination path in File Dialog Picker
I have a form that have two text boxes as Source and Target. The Source take the source path and the destination textbox xopy the file to the destination path. Copying file is working well, i want that when the user copy the file from Source to destination in file dialog picker it also take the file name when the destination is open from source with it's extension. Is there a way to achieve this?
Private Sub txtSource_Click() Dim Dialog As FileDialog Dim Selected As Long Set Dialog = FileDialog(msoFileDialogFilePicker) With Dialog .AllowMultiSelect = False .InitialFileName = Nz(Me!txtSource.Value) .Title = "Select file to copy" Selected = .Show If Selected <> 0 Then Me!txtSource.Value = .SelectedItems.Item(1) End If End With Cancel = TrueEnd SubPrivate Sub txtTarget_Click()Dim Dialog As FileDialog Dim Selected As Long Set Dialog = FileDialog(msoFileDialogSaveAs) With Dialog .AllowMultiSelect = False .InitialFileName = Nz(Me!txtTarget.Value) .Title = "Name saved file" Selected = .Show If Selected <> 0 Then Me!txtTarget.Value = .SelectedItems.Item(1) TargetFile = .SelectedItems.Item(1) If Not IsNull(Me!txtSource.Value) Then FileCopy Me!txtSource.Value, Me!txtTarget.Value Me.txtTarget = Split(TargetFile, ":")(1) End If ' Application.FollowHyperlink Me.txtTarget End If End With Cancel = TrueEnd Sub
Any error pop up if you can guide me in this: it's run time error says "Permission Denied contact Administrator", i am the administrator of the server and the write permission is set to yes. When i manually copy the file it's working but when i try to copy using this VBA code it's giving this error. Although considering the file gets copied but still it's poping up this error, do you have any idea about this?
Thank you Gustav.