Results 1 to 2 of 2
  1. #1
    g4tv4life is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    50

    Filecopy Question, how can I save the extension of the file?

    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

  2. #2
    drexasaurus's Avatar
    drexasaurus is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Santa Ana, CA
    Posts
    60
    The path seems to be selected via the line ".SelectedItems(1)". You could store this in a variable and do more work:
    Dim exten as String, dotInPath As Integer, path As String
    path = .SelectedItems(1)
    dotInPath = InStrRev(path, ".")
    exten = right(path, len(path) - dotInPath)
    ----
    This would get how many characters into the string the final period appears, and do math against the length of the entire path to pull out just the extension. From there, you could use it however you needed in that variable.
    Note that some extensions get kind of funky and filenames and directories can have periods in them, but in practice getting that last period character should work out.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Pulling data from text file with custom extension
    By dep999 in forum Import/Export Data
    Replies: 7
    Last Post: 02-07-2014, 01:28 PM
  2. FileCopy
    By thescottsman92 in forum Access
    Replies: 1
    Last Post: 09-02-2013, 04:35 PM
  3. Replies: 5
    Last Post: 11-18-2012, 05:12 PM
  4. how to display the extension file access 2007
    By tintincute in forum Access
    Replies: 4
    Last Post: 08-04-2010, 10:09 AM
  5. access file extension help
    By supertech33 in forum Access
    Replies: 2
    Last Post: 02-17-2010, 03:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums