oxicottin
Learning by pecking away....
- Local time
- Today, 10:02
- Joined
- Jun 26, 2007
- Messages
- 888
Hello I have a module that works so far as in it remaps my drives like I want but at the end of the code I want to run a function AutoLinkManager. It just skips over the relink.
Code:
'Global variable for path to original database location
Public gDBPath As String
Public Sub RemappingDrives()
Dim BatchFile As String
Dim strKillFile As String
Dim strRestart As String
'Sets the file name and location from your global variable
strKillFile = gDBPath
'Sets the file name of the temp batch file
BatchFile = CurrentProject.Path & "\RemappingDrives.cmd"
'Sets the restart file name
strRestart = """" & strKillFile & """"
'Creates the batch file
Open BatchFile For Output As #1
Print #1, "Echo Off"
Print #1, "ECHO Remapping Drives P: X: G: H:"
Print #1, "ping 127.0.0.1 -n 5 -w 1000 > nul"
Print #1, ""
Print #1, "net use P: \\weir-ms-001\weir-public /persistent:yes"
Print #1, "net use x: \\weir-ms-001\weir-appdata /persistent:yes"
Print #1, "net use G: \\weir-ms-001\weir-groupdata /persistent:yes"
Print #1, "net use h: \\weir-ms-001\weir-home /persistent:yes "
Print #1, ""
Print #1, "ECHO Restarting Microsoft Access..."
Print #1, "START /I " & """MSAccess.exe"" " & strRestart
Print #1, ""
Print #1, "ECHO Relinking Tables...."
Print #1, "/X ""AutoLinkManager"""
Print #1, "PAUSE"
Print #1, "ECHO Deleting temp batch file...."
Print #1, "Del """ & BatchFile & """"
Close #1
'Runs the batch file
Shell BatchFile
'Closes the current version and runs the batch file
DoCmd.Quit
End Sub
Public Sub AutoLinkManager()
Dim dbFE As DAO.Database
Dim dbBE As DAO.Database
Dim tdf As TableDef
Dim tdf1 As TableDef
Dim strFEFile As String
Dim strBEFile As String
Dim strTblName As String
strBEFile = DLookup("be_masterlocation", "tbl-version_master_location")
strFEFile = DLookup("fe_masterlocation", "tbl-version_master_location")
Set dbFE = DBEngine.Workspaces(0).OpenDatabase(strFEFile)
Set dbBE = DBEngine.Workspaces(0).OpenDatabase(strBEFile)
On Error Resume Next
For Each tdf1 In dbBE.TableDefs
strTblName = tdf1.Name
If Left(strTblName, 4) <> "msys" Then
dbFE.TableDefs.Delete strTblName
Set tdf = dbFE.CreateTableDef(strTblName)
tdf.Connect = ";DATABASE=" & strBEFile
tdf.SourceTableName = strTblName
dbFE.TableDefs.Append tdf
End If
Next tdf1
Set dbBE = Nothing
Set dbFE = Nothing
MsgBox "Linking Complete", vbInformation
End Sub