title: Changing a linked table file path to OS username in VBA?
body: <p>I have linked tables in an Access Database. I want to share this database and the associated excel workbooks with other users. I want to program a one-time use macro that the user will use the first time they use the database to relink the linked tables to the new user's local folder. </p>
  
  <p>For example:</p>
  
  <p>The linked table is current pulling the file from:<br>
  C:\Users\jane.doe\Desktop\Database Imports\Premier Account List.xlsx</p>
  
  <p>When the new user (let's say their name is John Smith) relinks the table, it needs to read:
  C:\Users\john.smith\Desktop\Database Imports\Premier Account List.xlsx</p>
  
  <p>I basically want to change the file path from my OS Username to new user's OS Username. I already have the code to pull the OS Username, but I'm not sure how to code changing the file path. Here is the code to pull the OS UserName:</p>
  
  <pre><code>Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
  "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  
  Function fOSUserName() As String
  
  ' Returns the network login name
  Dim lngLen As Long, lngX As Long
  Dim strUserName As String
  
  strUserName = String$(254, 0)
  lngLen = 255
  lngX = apiGetUserName(strUserName, lngLen)
  
  If (lngX &gt; 0) Then
      fOSUserName = Left$(strUserName, lngLen - 1)
  Else
      fOSUserName = vbNullString
  End If
  
  End Function
  </code></pre>
  
  <p>I am fairly new to VBA/Access, so if you could be as specific as possible with your answer, that would be great. Thanks in advanced!</p>