Hey everyone, I have a file attacher system here that selects a file (using dialog), renames it then filecopys it to a folder.
my problem is, how do i extract the file extension from the .selected items, so that any filetype can be attached?
here's me current code:
any ideas?
Code:
Private Sub Command183_Click()
Dim fDialog As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim varFile As Variant
' 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 Invoice to Attach"
' 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), GetDBPath() & "\Invoices\" & Me.[ID Number].Value & " " & Me.Asset.Value
Me.Invoice.Value = GetDBPath() & "\Invoices\" & Me.[ID Number].Value & " " & Me.Asset.Value
Else
'this code saves it as its original name- saved for archive purposes in case above doesnt work
'FileCopy .SelectedItems(1), GetDBPath() & "\Invoices\" & Dir(Trim(.SelectedItems.Item(1)))
' Me.Invoice.Value = Dir(Trim(.SelectedItems.Item(1)))
End If
End With
If IsNull(Me.Text115) Then
Me.Image206.Picture = GetDBPath() & "Images\Other\NoInvoice.jpg"
Else
Me.Image206.Picture = GetDBPath() & "Images\Other\YesInvoice.jpg"
End If
Me.Text182.Requery
End Sub