Came across two nifty functions that enable you to find out the name and path of the currently open database for people using Access 97. Thought it would be of use. I mostly use it in the footers of my reports combined with the CurrentObjectName function to help me figure out which report came from which app.
If you're using Access 2000/2002 you can utilize this instead for the database filename:
Or this for the database path:
Hope you found this as helpful as I did!
Theresa
"Sleep is the best meditation." - Dalai Lama
Code:
Public Function GetDbPath() As String
Dim myDB As Database
Set myDB = CurrentDb()
GetDbPath = myDB.Name
End Function
Public Function GetDBName()
Dim myDB As Database
Dim myDBPath As String
Dim intPosition1 As Integer
Dim intPosition2 As Integer
Set myDB = CurrentDb()
myDBPath = myDB.Name
intPosition1 = Len(myDBPath)
intPosition2 = InStr(1, myDBPath, "\")
If intPosition2 = 0 Then
MsgBox "Error", vbCritical
Else
intPosition2 = InStr(intPosition1, myDBPath, "\")
Do While (intPosition2 < 1)
intPosition1 = intPosition1 - 1
intPosition2 = InStr(intPosition1, myDBPath, "\")
Loop
GetDBName = Right(myDBPath, Len(myDBPath) - intPosition2)
End If
End Function
If you're using Access 2000/2002 you can utilize this instead for the database filename:
Code:
CurrentProject.Name
Or this for the database path:
Code:
CurrentProject.Path
Hope you found this as helpful as I did!
Theresa
"Sleep is the best meditation." - Dalai Lama