Stripping file name from Path...

S

SF

Hi,

I have a button on a form to let user selecting the photo file and paste it
into a text box but I am unable to strip only the file name (file name +
extension)

Private Sub btnSelectPhoto_Click()
'On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
Dim strPathAndFile As String
Me.AllowDeletions = False
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files (*.jpg,
*.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
strFilter = ahtAddFilterItem(strFilter, "Uncompressed Image Files
(*.bmp, *.wmf)", "*.BMP, *.WMF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Choose an Image File")
Me.txtSourceFile = strPathAndFile
End Sub

Could somebody advice. Also, is it possible to set the InitialDir to 'My
Documents\My Pictures'. I am using Office 2003 with Windows XP

SF
 
D

Dirk Goldgar

SF said:
Hi,

I have a button on a form to let user selecting the photo file and
paste it into a text box but I am unable to strip only the file name
(file name + extension)

Private Sub btnSelectPhoto_Click()
'On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
Dim strPathAndFile As String
Me.AllowDeletions = False
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files
(*.jpg, *.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
strFilter = ahtAddFilterItem(strFilter, "Uncompressed Image Files
(*.bmp, *.wmf)", "*.BMP, *.WMF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Choose an Image File")
Me.txtSourceFile = strPathAndFile
End Sub

Could somebody advice. Also, is it possible to set the InitialDir to
'My Documents\My Pictures'. I am using Office 2003 with Windows XP

SF

If the user is forced to choose a file that already exists, you can use
the Dir() function on the result to get just the filename.ext, like
this:

Me.txtSourceFile = Dir(strPathAndFile)

See the following link for code to call the Windows API to get the
location of various special folders, including the "My Pictures" folder:

http://www.mvps.org/access/api/api0054.htm

With that code pasted into a standard module, you can say

strPathAndFile = ahtCommonFileOpenSave( _
InitialDir:=fGetSpecialFolderLocation(CSIDL_MYPICTURES), _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Choose an Image File")
 
S

SF

Thank you.
SF

Dirk Goldgar said:
If the user is forced to choose a file that already exists, you can use
the Dir() function on the result to get just the filename.ext, like
this:

Me.txtSourceFile = Dir(strPathAndFile)

See the following link for code to call the Windows API to get the
location of various special folders, including the "My Pictures" folder:

http://www.mvps.org/access/api/api0054.htm

With that code pasted into a standard module, you can say

strPathAndFile = ahtCommonFileOpenSave( _
InitialDir:=fGetSpecialFolderLocation(CSIDL_MYPICTURES), _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Choose an Image File")

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Attach File 4
attachment 9
Folder access (Access 2003) 1
Copying a File using API 1
code problem 6
Uploading a Picture 1
"Variable Not Defined" 6
Extracting file path and name 2

Top