
February 6th, 2004, 10:55 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Location: New York, NY, USA
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Function to Get Path of CurrentDB
Dear iluvstrats,
Here is one I wrote awhile ago, I've added some comments and instructiuons for use at the top. I've never encountered any errors using this.
*NOTE* You will need a reference set for Microsoft DAO Object Library
Code:
Function ThisDB(Optional DesiredData As String = "fullpath") As String
'================================================= ============================
'Copyright by Heather L. Floyd - Floyd Innovations - URL
' Updated 2-6-2004
'-----------------------------------------------------------------------------
' To return desired data about the current database file
'-----------------------------------------------------------------------------
' Parameters:
' ARGUEMENT : DESCRIPTION
'-----------------------------------------------------------------------------
' DesiredData (Optional) (String) : String indicating what data you want
' returned -
' "fullpath" or "path" or "filename"
' Default is "fullpath"
'-----------------------------------------------------------------------------
' Returns:
' String of data requested based on 'DesiredData' arguement
'-----------------------------------------------------------------------------
' Example:
'-----------------------------------------------------------------------------
' ThisDB("fullpath") or ThisDB()= "C:\My Documents\My Database.mdb"
' ThisDB("path") = "C:\My Documents\"
' ThisDB("filename") = "My Database.mdb"
'================================================= ============================
On Error GoTo ErrorCode
'Variables & values
Dim db As DAO.Database
Set db = CurrentDb()
Dim strDB As String
strDB = db.Name
Dim strFullpath, strPath, strFileName As String
strFullpath = strDB
Dim iLenSDB As Integer
Dim iDotLoc As Integer
Dim iSlashLoc As Integer
Dim strModSDB As String
Dim iLenModSDB As Integer
iLenSDB = Len(strDB)
iDotLoc = InStr(strDB, ".")
strModSDB = strDB
iLenModSDB = Len(strModSDB)
iSlashLoc = InStr(strDB, "\")
'Parse
Do Until iSlashLoc = 0
iLenModSDB = Len(strModSDB)
strModSDB = Right(strModSDB, iLenModSDB - iSlashLoc)
iSlashLoc = InStr(strModSDB, "\")
Loop
strFileName = strModSDB
iLenModSDB = Len(strModSDB)
strPath = Left(strDB, iLenSDB - iLenModSDB)
'Return value
If DesiredData = "" Then
ThisDB = strFullpath
ElseIf DesiredData = "fullpath" Then
ThisDB = strFullpath
ElseIf DesiredData = "path" Then
ThisDB = strPath
ElseIf DesiredData = "filename" Then
ThisDB = strFileName
End If
ExitCode:
Exit Function
ErrorCode:
Select Case Err.number
Case Else
MsgBox "Error " & Err.number & ": " & Err.Description, vbCritical, "HLFFileUtils.ThisDB"
Resume ExitCode
End Select
End Function
Hope this helps.
Heather
|