breezett93
New member
- Local time
- Today, 01:17
- Joined
- Jun 7, 2021
- Messages
- 20
I am implementing the front end auto-update solution by Frothingslosh that is from a thread on here I can't link to.
I am unable to add breakpoints. I guess that's not allowed in a module?? So, it's difficult to see what's really happening.
The first function works well. I get the alert that a new update is needed. The program closes to begin the update.
In the second function, the batch file does get created. However, the old version does not get deleted. The icon just moves to a different spot on the screen (alternating between one space down and one space up). Also, none of the three echo prompts in the batch file show up on screen.
Code:
Option Compare Database
Public Function CheckFrontEnd() As Integer
' ************************************************************
' Created by : Scott L Prince
' Parameters : None
' Result : Determines if backend can be reached, and if front end is the current version.
' Returns : 0 - Misc Error
' : 1 - No current version found in Version Manager file
' : 2 - Front end being run from master location
' : 3 - Master file path not found in Version Manager file
' : 999 - Front end current
' Date : 5-30-14
' Remarks : Based on previously-existing code by Bob Larson posted at StackOverflow
' Changes :
' *************** *********************************************
Dim FrontEndVersion As String 'Front end version number
Dim MasterVersion As String 'Master version number
Dim MasterPath As String 'Location of the master FE file
Dim BatchPath As String 'Location of the batch file that does the actual update
'Determine master version number.
MasterVersion = DLookup("fe_version_number", "tbl-version_fe_master")
'Determine if the database containing the version information can be accessed.
Select Case MasterVersion
Case ""
CheckFrontEnd = 1
Case Else
'Look up the path for the master file location.
MasterPath = DLookup("s_masterlocation", "tbl-version_master_location")
'Determine if the master file is being run rather than a local copy.
If Nz(MasterPath, "") = "" Then
'No master path was found. Return error value.
CheckFrontEnd = 3
ElseIf MasterPath = CurrentProject.Path Then
'The actual master file is the one being executed.
CheckFrontEnd = 2
Else
'Master file path found and is not being run. Determine the version number of the active front end.
FrontEndVersion = DLookup("fe_version_number", "tbl-fe_version")
'Compare the version number in the front end to the master version number.
Select Case (FrontEndVersion = MasterVersion)
Case True
'Return "OKAY" result.
CheckFrontEnd = 999
Case False
'Create the path for the batch file used to update the front end.
BatchPath = CurrentProject.Path & "\UpdateDbFE.cmd"
'Check for an already-existing BatchPath, and kill it if it exists.
If Dir(BatchPath) <> "" Then Kill BatchPath
'Notify the user that the application will update.
MsgBox "UPDATE REQUIRED" & vbCrLf & vbCrLf & _
"Your program is not the latest version." & vbCrLf & vbCrLf & _
"The front-end needs to be updated. The program will now close and then should reopen automatically.", _
vbCritical
'Execute 'UpdateFrontEnd'.
UpdateFrontEnd CurrentProject.Path & "\" & CurrentProject.Name, MasterPath
End Select
End If
End Select
End Function
Private Sub UpdateFrontEnd(ByVal LocalFilePath As String, ByVal MasterFileFolder As String)
Dim BatchFile As String
Dim MasterFilePath As String
Dim Restart As String
'Set the file name and location for the file to copy
MasterFilePath = MasterFileFolder & "\" & CurrentProject.Name
'Set the file name of the batch file to create
BatchFile = CurrentProject.Path & "\UpdateDbFE.cmd"
'Set the restart file name
Restart = """" & LocalFilePath & """"
'Create the batch file
Open BatchFile For Output As #1
Print #1, "@Echo Off"
Print #1, "ECHO Deleting old file..."
Print #1, ""
Print #1, "ping 127.0.0.1 -n 5 -w 1000 > nul"
Print #1, ""
Print #1, "Del """ & LocalFilePath & """"
Print #1, ""
Print #1, "ECHO Copying new file..."
Print #1, "Copy /Y """ & MasterFilePath & """ """ & LocalFilePath & """"
Print #1, ""
Print #1, "ECHO Starting Microsoft Access..."
Print #1, "START /I " & """MSAccess.exe"" " & Restart
Close #1
'Run the batch file
Shell BatchFile
'Close the current application so batch file can execute.
DoCmd.Quit
End Sub
I am unable to add breakpoints. I guess that's not allowed in a module?? So, it's difficult to see what's really happening.
The first function works well. I get the alert that a new update is needed. The program closes to begin the update.
In the second function, the batch file does get created. However, the old version does not get deleted. The icon just moves to a different spot on the screen (alternating between one space down and one space up). Also, none of the three echo prompts in the batch file show up on screen.