Results 1 to 9 of 9
  1. #1
    willkr is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2023
    Posts
    110

    Determing my directory and file name


    Is there a way to programmatically determine the directory and file name of the app being run?

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    ?CurrentProject.Name gets the name

    CurrentProject.Path will get you the path to the app. You can then parse out the directory.

    MyFolderName = Mid(CurrentProject.Path, InStrRev(CurrentProject.Path, "\") + 1)
    Last edited by moke123; 12-31-2023 at 07:24 PM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by willkr View Post
    Is there a way to programmatically determine the directory and file name of the app being run?
    Ever heard of google?
    https://www.google.com/search?q=dete...hrome&ie=UTF-8
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    willkr is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2023
    Posts
    110
    Yes, I tried about a dozen Google searches, but I didn't quite know how to phrase the question. Thank-you for your assistance!

  5. #5
    Salty Mariner is online now Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    69
    Quote Originally Posted by moke123 View Post
    ?CurrentProject.Name gets the name

    CurrentProject.Path will get you the path to the app. You can then parse out the directory.

    MyFolderName = Mid(CurrentProject.Path, InStrRev(CurrentProject.Path, "") + 1)
    Mokie, I saw you edited the expression because I tried the empty string and played with it until I tried the slash. I was starting to type this reply and then saw you had just edited it.

    I like the InStrRev I had never tried that before. My initial thought was something like

    Mid((CurrentProject.FullName), Len(CurrentProject.Path)+2, Len(CurrentProject.FullName)-Len(CurrentProject.Path))

    Your approach is way more efficient.

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I saw you edited the expression because I tried the empty string and played with it until I tried the slash. I was starting to type this reply and then saw you had just edited it.
    I just noticed it myself a few minutes ago and checked it. Because I didn't use code tags the slash didn't show. I edited it to add 2 slashes so the 1 showed like it should have.

    These 2 lines are the same. Weird only one shows the slash.

    InStrRev(CurrentProject.Path, "")
    Code:
    InStrRev(CurrentProject.Path, "\") 
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Your approach is way more efficient.
    There's always more than one way to do things in access.

    I should also point out you can do a similar thing with a linked backend file.

    Code:
    Public Function GetBackendPath() As String
    
        Dim tblName As String
        
        tblName = "tblPeople" 'the name of a linked table in the back end
     
        GetBackendPath = Mid(CurrentDb.TableDefs(tblName).Connect, _
            InStr(1, CurrentDb.TableDefs(tblName).Connect, "DATABASE=") + 9)
                            
        Debug.Print "The Connect String is " & CurrentDb.TableDefs(tblName).Connect
    
    
        Debug.Print "TheBackend Path = " & GetBackendPath
    
    
        Debug.Print "The Backend File Name is " & _
            Mid(GetBackendPath, InStrRev(GetBackendPath, "") + 1)
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    willkr is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2023
    Posts
    110
    Interesting discussion. Moke, you gave me the answer I needed in your first response. I want to be able to display the path and file name for customer support reasons. The most important thing is to tell me whether it is an accdb or and accde, since I have both installed in some cases. I have a hidden button that brings up a form with all the information I need now.

    Thanks again! You guys are great.

  9. #9
    willkr is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2023
    Posts
    110
    Interesting discussion. Moke, you gave me the answer I needed in your first response. I want to be able to display the path and file name for customer support reasons. The most important thing is to tell me whether it is an accdb or and accde, since I have both installed in some cases. I have a hidden button that brings up a form with all the information I need now.

    Thanks again! You guys are great.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Upload file and output that file to directory
    By SierraJuliet in forum Access
    Replies: 2
    Last Post: 01-13-2019, 09:28 PM
  2. Replies: 6
    Last Post: 09-14-2017, 07:31 AM
  3. File Directory in VBA
    By RayMilhon in forum Programming
    Replies: 1
    Last Post: 05-11-2016, 01:06 PM
  4. Replies: 1
    Last Post: 08-15-2015, 10:09 AM
  5. Replies: 2
    Last Post: 03-07-2014, 09:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums