How tell path where MDB invoked from ?

M

mscertified

Is there a way to get the file path from where the executing MDB file was
invoked. I want to enforce users running this split data base from a local
drive instead of a network drive. I can't use permissions to do this.

Thanks.
 
D

Douglas J Steele

CurrentDb.Name will give you the path of the current database, as will
CurrentProject.FullName
 
M

Marshall Barton

mscertified said:
Is there a way to get the file path from where the executing MDB file was
invoked. I want to enforce users running this split data base from a local
drive instead of a network drive. I can't use permissions to do this.


Depending on what you need try using:
CurrentDb().Name
or
CurrentProject.Path
 
L

Lateral

Hi Doug

I want the "path" to be displayed at the bottom of each form in my
application for support purposes.

How can I get this information onto a form? Please note that I am new to
Access 2003.

Thanks
Regards
Greg
 
S

strive4peace

Hi Greg,

you can use a calculated control. Make a textbox -->

Name --> dbPath
ControlSource --> =[currentproject].[path]

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
L

Lateral

Thanks Arvin,

I should have explained that my application is "split" with a FE (Front end)
and BE (Backend) database with the BE DB located on a network drive (eg:
T:\sample\) and that I want to be able to display the path of the BE DB (ie:
T\sample\).

What do I need to do?

Thanks
Regards
Greg
 
A

Arvin Meyer [MVP]

Try something like this (aircode):

Function Foo()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim temp As String
Set db = CurrentDb
Set tdf = db.TableDefs("tblBid") ' Any linked tablename

temp = tdf.Connect 'gets the backend path name

Do Until Right(temp, 1) = "\" ' removes the table name
temp = Left(temp, Len(temp) - 1)
Loop

temp = Mid(temp, 11) ' removes the DATABASE prefix
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
S

strive4peace

Hi Lateral,

Here is code to document Linked tables with:

1. Table Description from source database (if linked table comes from
Access)

2. path and file to linked filename (works with Access and Excel)

put these 2 procedures in a general module. You can assign the function
directly to an event directly using (ie:)
=DocLinkTables(true, true)

to just run the procedure, run the Sub, RunDocLinkTables
click in the code and press F5


'~~~~~~~~~~~ Document Linked Tables ~~~~~~~~~~~

'--------------- RunDocLinkTables
Sub RunDocLinkTables()
'run this Sub if you don't have an event assigned to DocLinkTables
'to run, click in this code and press F5
DocLinkTables True, True
End Sub

'--------------- DocLinkTables
Function DocLinkTables( _
pBooDesc As Boolean, _
pBooLink As Boolean) As Boolean

'written by crystal
'[email protected]

'needs reference to
'Microsoft DAO Library

'modifies Description of each table with
'Description from source table if pBooDesc=true
'path of linked database if pBooLink=true

'adds to Description if it already exists
'anything after ~ is replaced

'USEAGE
'assign to an event
' --> =DocLinkTables(true, true)

On Error GoTo Proc_Err

DocLinkTables = False

Dim dbCurrent As dao.Database, dbLink As dao.Database, numLinks As
Integer
Dim tdf As dao.TableDef, mMsg As String, mDesc As String, mProp As
Property
Dim dbLinkName As String, dbLinkNameLast As String, mPos As Integer

CurrentDb.TableDefs.Refresh
DoEvents

Set dbCurrent = CurrentDb
dbLinkName = ""
dbLinkNameLast = ""
numLinks = 0

For Each tdf In dbCurrent.TableDefs


SysCmd acSysCmdSetStatus, "Checking " & tdf.Name & "..."
mMsg = ""

'see if there is a connection string
If Len(tdf.Connect) > 1 Then

mPos = InStr(tdf.Connect, "Database=")
dbLinkName = Mid(tdf.Connect, mPos + 9)

If Left(tdf.Connect, 4) = "Text" Then
dbLinkName = dbLinkName & "\" & tdf.SourceTableName
End If

If pBooLink Then mMsg = dbLinkName


' make sure the file is valid
If Len(Dir(dbLinkName)) = 0 Then
mMsg = "Connection NOT VALID or no code to check --> " _
& mMsg
Else

Select Case True

'~~~ Access ~~~
Case Left(tdf.Connect, 10) = ";DATABASE="


'if this is the same database we just accessed
' use same dbLink
If dbLinkName <> dbLinkNameLast Then

If dbLinkNameLast <> "" Then dbLink.Close
Set dbLink = OpenDatabase(dbLinkName)
dbLinkNameLast = dbLinkName

End If

If pBooDesc Then

On Error Resume Next

mMsg = Nz(dbLink.TableDefs( _
tdf.SourceTableName).Properties("Description") _
, "") & " ~" _
& mMsg

On Error GoTo Proc_Err

End If


'~~~ Excel ~~~
Case Left(tdf.Connect, 5) = "Excel"
mMsg = "Excel > " & mMsg

'~~~ Text ~~~
Case Left(tdf.Connect, 4) = "Text"
mMsg = "Text > " & mMsg


'~~~ Not Access or Excel ~~~
Case Else
MsgBox "No Code written to add more to -->" _
& tdf.Connect, , "Need to Add code"

End Select

End If

If Len(mMsg) = 0 Then mMsg = "Linked table"

If Len(mMsg) > 0 Then
On Error Resume Next
mDesc = Nz(tdf.Properties("Description"), "")
On Error GoTo Proc_Err

If InStr(mDesc, "~") > 0 Then
mDesc = Trim(Left(mDesc, InStr(mDesc, "~") - 1))
End If

mDesc = mDesc & " ~" & mMsg

With tdf
numLinks = numLinks + 1
On Error Resume Next
Set mProp = .CreateProperty("Description", dbText, mDesc)
.Properties.Append mProp
If Err.Number > 0 Then .Properties("Description") = mDesc
On Error GoTo Proc_Err
End With
End If
End If


Next tdf

CurrentDb.TableDefs.Refresh
DoEvents

DocLinkTables = True

MsgBox "Done Documenting Tables: " _
& numLinks & " Linked Table Descriptions changed" _
, , "Done Documenting Tables"

Proc_Exit:
On Error Resume Next
Set mProp = Nothing
Set tdf = Nothing
Set dbCurrent = Nothing
dbLink.Close
Set dbLink = Nothing

SysCmd acSysCmdClearStatus

Exit Function

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number & " DocLinkTables" _
& IIf(TypeName(tdf) <> "nothing", ": " & tdf.Name, "")

'press F8 to step through code and debug
'remove next line after debugged
Stop: Resume
Resume Proc_Exit
End Function

'~~~~~~~~~~~~~~~~~~~~


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
L

Lateral

Hi Guys

Thanks for you help.

I found a function called "WhereAttached()" in a module that I implemented
to automatically backup by BE database.

Thanks again.
Regards
Greg
 
Top