Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 5th, 2004, 05:08 PM
iluvstrats iluvstrats is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 iluvstrats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Function to return path of Currentdb

Is there a function that returns the path or directory of the CurrentDb?

Last edited by iluvstrats : February 5th, 2004 at 05:12 PM.

Reply With Quote
  #2  
Old February 6th, 2004, 11:55 PM
HFloyd HFloyd is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: New York, NY, USA
Posts: 1 HFloyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb 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

Reply With Quote
  #3  
Old February 12th, 2004, 03:20 PM
iluvstrats iluvstrats is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 iluvstrats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Function or command to return the path of an attached table?

Thanks. That worked great.

One more thing. Is there a function or command to return the path of of an attached table?

Reply With Quote
  #4  
Old October 30th, 2009, 01:59 PM
loopback loopback is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 1 loopback User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m
Reputation Power: 0
OK, so I'm a few years late, but here is an updated version of the code posted by Heather.

Fixed:
-Removed irrevelent variables
-Removed loop to find last backslash
-Added Enum to make return options more clear
-Added SELECT structure to make code a little more clear

Thanks for this, Heather!

Code:
Public Enum PathFormat
    FullPath = 0
    Path = 1
    FileName = 2
End Enum

Function ThisDB(Optional DesiredData As PathFormat = FullPath) As String
'=================================================    ============================
'Copyright by Heather L. Floyd - Floyd Innovations - URL
' Updated 2-6-2004
' Updated 10-30-2009 by Loopback (loopback@gregs-domain.net)
'-----------------------------------------------------------------------------
' 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 strFullPath As String
    Dim strPath As String
    Dim strFileName As String
    Dim intSlashPosition As Integer

    strFullPath = CurrentDb().Name
    intSlashPosition = InStrRev(strFullPath, "\")
    strFileName = Mid(strFullPath, intSlashPosition + 1)
    strPath = Left(strFullPath, intSlashPosition)
    

'Return value
    Select Case DesiredData
        Case 0:
            ThisDB = strFullPath
        Case 1:
            ThisDB = strPath
        Case 2:
            ThisDB = strFileName
        Case Else
            ThisDB = strFullPath
    End Select

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

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Function to return path of Currentdb


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek