Is there a way to programmatically determine the directory and file name of the app being run?
Is there a way to programmatically determine the directory and file name of the app being run?
?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
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
Yes, I tried about a dozen Google searches, but I didn't quite know how to phrase the question. Thank-you for your assistance!
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.
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.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.
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
There's always more than one way to do things in access.Your approach is way more efficient.
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
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.
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.