I'm using db.Name (where db is the database object) to retrieve the name of my database but it returns the full path. How can I get just the name, stripping out the path?
Example:
I get - C:\My Documents\mydatabase.mdb
I want - mydatabase
Printable View
I'm using db.Name (where db is the database object) to retrieve the name of my database but it returns the full path. How can I get just the name, stripping out the path?
Example:
I get - C:\My Documents\mydatabase.mdb
I want - mydatabase
Since you can't use \ in a name, anything after the last \ must be the database name so use InStr to locate the position of the last \ and then use Right$
That will do it, but there may be more efficient ways of doing it.Code:Dim iPos as Integer, strName as String
Do While InStr(iPos + 1, db.Name, "\") <> 0
iPos = InStr(iPos + 1, db.Name, "\")
Loop
strName = Right$(db.Name, Len(db.Name) - iPos)
Cheers,
P.