[AccessD] Common Dialog

Max Wanadoo max.wanadoo at gmail.com
Thu Jan 7 11:34:27 CST 2010


Why not something simple like this..

Function x()
    ' the following two examples will both give the same result.
    Dim str As String
    str = "c:\myfile.txt"
    str = Mid(str, InStrRev(str, "\") + 1)
    Debug.Print str
    str = "myfile.txt"
    str = Mid(str, InStrRev(str, "\") + 1)
    Debug.Print str
End Function

So, all you need is 

str = Mid(str, InStrRev(str, "\") + 1)

Max


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan, Lambert
Sent: 07 January 2010 17:21
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Common Dialog

Here's a simple function to return the file path...

Function GetPath(aPath) As String
' Strips the path name from the supplied file and path name
' leaves the trailing slash on there
Dim foo As Integer, aSlash As Integer
    aSlash = 0
    foo = InStr(aPath, "\")
    While (foo > 0)
        aSlash = foo
        foo = InStr(aSlash + 1, aPath, "\")
    Wend
    If aSlash > 0 Then
        GetPath = left$(aPath, aSlash)
    Else
        GetPath = ""
    End If
End Function

And using that you can get the file name...

Function GetFileName(aPath) As String
Dim fPath As String
    fPath = GetPath(aPath)
    If Len(fPath) = Len(aPath) Then ' only a path was provided
        GetFileName = ""
    Else
        GetFileName = right$(aPath, Len(aPath) - Len(fPath))
    End If
End Function

These two functions were written back in Access 97 days, before the Split()
function came to be. With split you could do something like this (air
code)...

Function GetFileName(sPath as String) as String
vArray as Variant
	vArray = Split(sPath,"\")
	GetFileName = Cstr(Ubound(vArray))
End Function
 

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Lawrence Mrazek
Sent: Thursday, January 07, 2010 12:00 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] Common Dialog

Hi Folks:

I'm the API from http://www.mvps.org/access/api/api0001.htm, and can't seem
to remember how to ONLY retrieve the filename (not the filename and path
using the API. 

I suppose that if I know the directory, I can use some functions to trim off
the directory path, but in this case I might not always be looking for the
files in a default directory.

Any hints/guidance would be appreciated. 

Larry Mrazek
lmrazek at lcm-res.com
314-432-5886



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list