Forum Discussion

jgsudderth's avatar
jgsudderth
New Member
2 years ago
Solved

Help with Dynamic File Path without using parameters

I am importing an access database.  My current M code is the following:  

 

 

let
    Source = Access.Database(File.Contents("C:\Users\John\Company Finance Dropbox\Accounting and Finance\Access Databases\Daily Sales Snapshot v6.0.accdb"), [CreateNavigationProperties=true]),

 

 

The problem is when another person tries to use this file, the references break because of the hard coded file Reference to "John".  Everything else will be the exact same.  I have read 25+ articles on how to make this a reference and figured it out yesterday but can't remember which of the million options I tried made it work.  

 

I'd like instead of "John" to be the current username of whoever is working on the report.  It may be Jack, Jill, etc. but everything else will be the same.  I can't remember how to pull the current file path.  There was a query I wrote (maybe it was a function) that gave me that filepath, and then I could replace the hardcoded part of the filepath with a reference to that query.

 

Thanks for your help!

3 Replies

  • jgsudderth maybe create a parameter with the name value and replace the name with the parameter, so anytime the parameter value is changed, it will update the path.

    • jgsudderth's avatar
      jgsudderth
      New Member

      The problem is I don't know if it will be Jack, Jill, Jack 2, etc.  I'd like to future-proof this as much as possible so pulling the current user via a file path function and then inserting that would allow me to not know EVERY username that could ever use the file.  Unfortunately laptops and desktops all create new "usernames" as part of that dropbox file reference.