Alright, This is what I came up with. I finally found a difference between the 3 regions. The homedrive, so that is what I am using. What this code does is first, deletes the linked table to the backend. Then starts figuring out where to rebuild the link.
So we have 3 regions, each region uses a different homedrive letter. But then again we also have remote employees who work from home. Thankfully those people all use the same vpn client, and I can check for the running process. Here is the code. Lastly, if somehow a user avoids all of these statements, it will create a link to a misfit database as backup. Thoughts? Comments?
Code:
Sub BackendLink()
Dim strTerminateThis As String
Dim objWMIcimv2 As Object, objProcess As Object, objList As Object
Dim intError As Integer
Dim oTD As DAO.Database
If TableExists("UseLog") = True Then
DoCmd.DeleteObject acTable, "UseLog"
End If
Home = Environ("homedrive")
''''''''''''''''''''''''''''''''''Determine if user is on VPN...
strTerminateThis = "vpnui.exe" ' The cisco vpn client process, if its there they are remote.
Set objWMIcimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objList = objWMIcimv2.ExecQuery("select * from win32_process where name='" & strTerminateThis & "'")
For Each objProcess In objList
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\networkpath\BackendDataRemotes.accdb", acTable, "UseLog", "UseLog"
Exit Sub
If intError <> 0 Then Exit For
Next
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
'''''''''''''''''''''''''''''''''
If Home = "P:" Then
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\networkpath\BackendDataWest.accdb", acTable, "UseLog", "UseLog"
Exit Sub
End If
If Home = "U:" Then
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\networkpathBackendDataCentral.accdb", acTable, "UseLog", "UseLog"
Exit Sub
End If
If Home = "W:" Then
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\networkpath\BackendDataEast.accdb", acTable, "UseLog", "UseLog"
Exit Sub
End If
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\networkpath\BackendDataMisfits.accdb", acTable, "UseLog", "UseLog"
End Sub
Function TableExists(strTableName As String) As Boolean
On Error Resume Next
TableExists = IsObject(CurrentDb.TableDefs(strTableName))
End Function