hi ,all
i struggling to check a directory see if a file exists
current the code i have the user selects the file from the file picker it then copies the file to another folder to stop people linking it to there personal drive, but the issues is i need to check that the file they are selecting doesn't already exist in the folder it's being copied too. Some how i need to cross referance path1 to .selected items (1)
thanks in advance
Shane
i struggling to check a directory see if a file exists
current the code i have the user selects the file from the file picker it then copies the file to another folder to stop people linking it to there personal drive, but the issues is i need to check that the file they are selecting doesn't already exist in the folder it's being copied too. Some how i need to cross referance path1 to .selected items (1)
Code:
Dim fDialog As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim varFile As Variant
Dim path1 As String
path1 = "C:\Users\ss\Desktop\Test Folder" ' [COLOR="Red"]help here this is the folder i want to check if the file the user picks is already one named the same if so message sorry name in use exit sub[/COLOR]
' Set up the File Dialog. '
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
fd.InitialFileName = Application.CurrentProject.Path
With fDialog
' Allow user to make multiple selections in dialog box '
.AllowMultiSelect = False
' Set the title of the dialog box. '
.Title = "Please select a Image"
' Clear out the current filters, and add our own.'
.Filters.Clear
.Filters.add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the '
' user picked at least one file. If the .Show method returns '
' False, the user clicked Cancel. '
If .Show = True Then
' This section takes the selected image and copy's it to the generated path'
' the string takes the file location, navigates to the image folder, uses the combo box selection to decide the file category, then uses the name from the filedialog to finish the path'
FileCopy .SelectedItems(1), path1 & "\" & Dir(Trim(.SelectedItems.Item(1)))
Me.Cert.Value = path1 & "\" & Dir(Trim(.SelectedItems.Item(1)))
Me.Last_Scan_Date = Now()
Else
End If
'ADD this line
Cancel = True
End With
End Sub
thanks in advance
Shane