Subroutine to display pathname

  • Thread starter Thread starter Karen
  • Start date Start date
K

Karen

Hello All -

My database links to a user's database. User's may have
stored their database in different locations. One user
might have it on their local drive, another user might
have it on a network, etc. I already have the code to
actually link my database to their database. Works
great. I would like to now create a subroutine that would
return the pathname/location of where the user's database
resides. So if my database is installed at a user's
location and they have their own data stored at: "C:\My
Documents\Data\userdata.mdb" ~~~ how do I go about writing
a routine that will tell me that so that I can display it
on the startup form?

Ahhhh ~ Thanks, Karen
 
Karen said:
Hello All -

My database links to a user's database. User's may have
stored their database in different locations. One user
might have it on their local drive, another user might
have it on a network, etc. I already have the code to
actually link my database to their database. Works
great. I would like to now create a subroutine that would
return the pathname/location of where the user's database
resides. So if my database is installed at a user's
location and they have their own data stored at: "C:\My
Documents\Data\userdata.mdb" ~~~ how do I go about writing
a routine that will tell me that so that I can display it
on the startup form?

Ahhhh ~ Thanks, Karen

Pick any of the linked tables and extract the path from that table's
Connect property. Here's a function I use in one of my applications:

'---- start of code ----
Function fncDataDBName() As String

' Return the name (including path) of the "back-end" database
containing the data
' this application is working with. If the data tables are local,
not linked, return
' the name of the current database.

Static strDBFileName As String

If Len(strDBFileName) = 0 Then
strDBFileName = CurrentDb.TableDefs("tblProfile").Connect
If Left$(strDBFileName, 10) = ";DATABASE=" Then
strDBFileName = Mid$(strDBFileName, 11)
Else
strDBFileName = CurrentDb.Name
End If
End If

fncDataDBName = strDBFileName

End Function
'---- end of code ----

You would have to replace "tblProfile" with the name of one of the
linked tables in your database.
 
Karen said:
Hello All -

My database links to a user's database. User's may have
stored their database in different locations. One user
might have it on their local drive, another user might
have it on a network, etc. I already have the code to
actually link my database to their database. Works
great. I would like to now create a subroutine that would
return the pathname/location of where the user's database
resides. So if my database is installed at a user's
location and they have their own data stored at: "C:\My
Documents\Data\userdata.mdb" ~~~ how do I go about writing
a routine that will tell me that so that I can display it
on the startup form?

CurrentDB.Name will return the full path to the file along with the name of the file
itself.
 
Back
Top