Results 1 to 2 of 2

Thread: Getting name of database (Access - VBA)

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    49
    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

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    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$

    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)
    That will do it, but there may be more efficient ways of doing it.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width