Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - Get file name our of file Path 1

Status
Not open for further replies.

mds82

MIS
Oct 7, 2005
10
US
First off - this is my first posting here so i want to thank everyone in advance for help now and in the furture. I'm not much of a progamer, bur rather a network admin working on a project for my boss. Anyways...
in Access i have a command button that prompts the user to select a PDF or TIF file on their computer. I need to be able to copy that selected file to our server. i cant figure out ho how to do this however. so far this is the code that i have.

Private Sub BtnAttachFile_Click()

Dim strPath As String, FileLoc As String, , Frm As Form, FileName As String
Dim strExt As String, strExtDesc As String, intCurrentRow As Integer
Set Frm = Forms!PartNumbers
strExt = "tif;tiff;pdf"
strExtDesc = "Tif images and pdf files (*.pdf, *.tif)"
strPath = GetFile("Link", strExtDesc, strExt)

If IsBlank(strPath) Then
GoTo cmdLink_Click_Exit
Else
MsgBox ("File is: " & strPath)
FileLoc = strPath
FileName = strPath
End If


Now - the FileLoc is the full directory - ex "c:\docs and settings\username\desktop\file.pdf" i dont know how to just find the name of the "file.pdf"

Thanks for the help!
 
FileName = Mid(FileLoc, 1 + InStrRev(FileLoc, "\"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV - that worked quite nicely and was much easier then i though. i just wish i knew VBA commands
 
try this...

Code:
Public Function GetFileFromPath(sFileLoc)
dim a as integer, s as string

for a = len(SfileLoc) to 1 step -1
   s = left(right(sFileLoc),a),1)
   if s = "\" then
      exit for
   end if
next a

If s = "\" then
   GetFileFromPath = right(sFileLoc, len(sFileLoc)-a)
else
   GetFileFromPath = sFileLoc
End if
End Function
 
Sometimes I am just a brute force kind of programmer. I knew the InStrRev functionality had to be out there, but I never looked it up.

Learn something new every day.

I'll give you a star for that one, PHV.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top