Results 1 to 9 of 9
  1. #1
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32

    Determining a files extension?


    Hello,

    I need to find a files extension so that I can add an attachment to an email.

    I know the folders pathway and the files will have a specific number but the files range from office docs to images.

    The file number will relate to a field in my db, so that when the email is generated it knows which file to look for and attach.

    I assumed that I could use something like "C:folder\file\" & me.field & "*" but when using * it tells me that the file doesn't exist.

    Any help you be great.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Extract file extension with string manipulation. x represents the file name.

    Right(x, InStrRev(x, ".") - 1)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32
    Would x have to have the extension or can I just supply "C:folder\file\" & me.field and some how it finds the extension?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Provide it any string you want. It will pull all characters following the first period from the right.

    This assumes all strings have a file extension.

    If you also assume all extensions are 3 characters, can be simply: Right(x, 3)

    Consistency in data is critical.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32
    Thank you! I shall try this in the morning.

  6. #6
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32
    Here is the quick test I used:

    FileName = "C:\Users\Paul\Desktop\templates\" & Me.field & "."

    test = Right(FileName, InStrRev(FileName, ".") - 1)

    MsgBox (test)

    message box shows "C:\Users\Paul\Desktop\templates\1."


    If I provide it with a the extension also the message box shows : "C:\Users\Paul\Desktop\templates\1.docx"


    any ideas?

  7. #7
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32
    Right(FileName, Len(FileName) - InStrRev(FileName, ".")) This code seems to separate the extension from the path name, but the extension has to be supplied in the FileName.

    I can only supply it with the pathname without the knowing the extension.

  8. #8
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in your vba window immediate section

    if you type the following and hit enter

    ?Dir("C:\Users\Paul\Desktop\templates\" & "1.*")

    it should return the first file called 1.extension where extension is docx, xlsx or whatever

    so what you may need to do is use the Dir function to return the name which you can then pass to your email

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Sorry, guess I should have used Mid instead of Right. I did test the Right and thought it was pulling just the extension, now not sure what I was doing before.

    Mid(x, InStrRev(x, ".")+1))

    The file name is stored in the table with the extension?

    I am not really understanding your statement "I can only supply it with the pathname without the knowing the extension." What exactly do you want?
    You want to pull and use the extension from the filename OR you want to cut the extension from the file name?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Determining a Control's Subscript
    By The Professor in forum Forms
    Replies: 1
    Last Post: 12-13-2012, 08:56 AM
  2. Determining the value of 3 Date/Time Boxes....Newbie
    By REAbernathy in forum Programming
    Replies: 3
    Last Post: 09-12-2012, 12:05 PM
  3. Database with extension mld
    By kstieb in forum Import/Export Data
    Replies: 6
    Last Post: 09-06-2012, 12:38 PM
  4. Determining cause of Update event
    By RJosephNewton in forum Access
    Replies: 3
    Last Post: 03-25-2010, 04:34 PM
  5. Determining Winners/Losers
    By pfeff in forum Queries
    Replies: 0
    Last Post: 02-21-2008, 03:46 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