Hi,
I am attempting to write a code that will:
1) copy the current database from the network to their C:\drive so they can access it from there going forward
2) check for a new version of the database and update to the new version
Currently, it will run the CERT.bat file to create/copy the database but it doesn't recognize to update it to the new version.
I have the following:
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrorHandler
Dim sPath As String
sPath = CurrentProject.Path
MsgBox sPath, vbOKCancel
Me.Caption = "- Cost Estimating Request Tool v" & Version
'TODO Update app title based on 'Version'
If IsACCDE Then
' MsgBox "Made It" 'DEBUG
DoCmd.SelectObject acTable, , True
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.RunCommand acCmdWindowHide
Application.SetOption "Show Status Bar", False
'Check if running from Network location (currentproject.path)
If InStr(1, sPath, NetCheck, vbTextCompare) > 0 Then
'Case yes - install to c/estimating w/desktop shortcut
MsgBox "You are currently trying to run the Estimating Request Tool from the Network." & vbNewLine & " A local version will be installed, and a shortcut copied to your Desktop.", _
vbCritical + vbOKOnly, "Install Estimating Request Tool"
UpdateApplication
Else
'case no - check version
Dim sVer As Double
sVer = CDbl(DLookup("Version", "tbl_Global_Settings", "App='EstimateRequest'"))
If sVer > Version Then
MsgBox "A new version of the Request Tool is available." & vbNewLine & "The update will be automatically installed to your computer.", _
vbCritical + vbOKOnly, "Estimating Request Tool: Update Needed"
UpdateApplication
End If
End If
End If
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Number & ", " & Err.Description
Exit Sub
End Sub
These are in a Module
Code:
Public Const Version As Double = 2.8
Code:
Public Sub UpdateApplication() 'Byval NewInstall as boolean
'if true then
' case 1 new install current code works,
' case 2 update from local copy - need to close and run batch file to copy and restart.
Dim DestPath As String
DestPath = "C:\Estimating\Request Tool"
If Dir("c:\Estimating", vbDirectory) = "" Then
MkDir "C:\Estimating"
End If
If Dir("c:\Estimating\Request Tool", vbDirectory) = "" Then
MkDir "C:\Estimating\Request Tool"
End If
sPath = DLookup("InstallSourcePath", "tbl_Global_Settings", "App='EstimateRequest'")
Dim FSOLibrary As Object
Dim FSOFolder As Object
Dim FSOFile As Object
'Set all the references to the FSO Library
Set FSOLibrary = CreateObject("Scripting.FileSystemObject")
Set FSOFolder = FSOLibrary.GetFolder(sPath)
Set FSOFile = FSOFolder.Files
'Use For Each loop to loop through each file in the folder
For Each FSOFile In FSOFile
Debug.Print FSOFile.Name
FSOLibrary.CopyFile sPath & "\" & FSOFile.Name, DestPath & "\" & FSOFile.Name
DoEvents
Next
DestPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Cost Estimating Request Tool.lnk"
If Dir("C:\Estimating\Request Tool\Cost Estimating Request Tool.lnk") <> vbNullString Then
FSOLibrary.CopyFile "C:\Estimating\Request Tool\Cost Estimating Request Tool.lnk", DestPath, True
End If
'Release the memory
Set FSOLibrary = Nothing
Set FSOFolder = Nothing
Set FSOFile = Nothing
'Dim sAppPath As String, retval
'sAppPath = Application.SysCmd(acSysCmdAccessDir) & "msaccess.exe"
'retval = Shell(sAppPath & " " & vbDoubleQuote & "C:\Estimating\Request Tool\Cost Estimating Request Tool.accde" & vbDoubleQuote
If Dir("C:\Estimating\Request Tool\CERT.bat") <> vbNullString Then
Shell ("C:\Estimating\Request Tool\CERT.bat")
Else
WriteBATFile
End If
DoEvents
DoCmd.Quit acQuitSaveNone
End Sub
Code:
Private Sub WriteBATFile()
Dim fs As Object, a As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("C:\Estimating\Request Tool\CERT.bat", True)
Debug.Print "START /B " & vbDoubleQuote & "Access" & vbDoubleQuote & " " & vbDoubleQuote & "C:\Estimating\Request Tool\Cost Estimating Request Tool.accde" & vbDoubleQuote
a.WriteLine ("START /B " & vbDoubleQuote & "Access" & vbDoubleQuote & " " & vbDoubleQuote & "C:\Estimating\Request Tool\Cost Estimating Request Tool.accde" & vbDoubleQuote)
a.WriteLine ("EXIT")
a.Close
Shell ("C:\Estimating\Request Tool\CERT.bat")
'START /B "Access" "C:\Estimating\Request Tool\Cost Estimating Request Tool.accde"
'EXIT
End Sub