'Script to do some setup
Dim objFso, blnFolderExists, blnFeExists, strNetworkFolder, strDeployFolder
Dim strFe, varRetVal, blnLocalIsCurrent, strMsg

strNetworkFolder = "\\orion\shared\TestApp"
strDeployFolder = "C:\Dev\TestApp"
strFe = "MyFE.accdb"

Set objFso = CreateObject("Scripting.FileSystemObject")
blnFolderExists = objFso.FolderExists(strDeployFolder)
blnFeExists = objFso.FileExists(strDeployFolder & "\" & strFe)

If blnFolderExists = False Or blnFeExists = False Then
	'Deploy whole front end including shortcut
	DoFullDeploy objFso, strNetworkFolder, strDeployFolder, strFe, blnFolderExists
Else
	'Check version to see if it is up to date
	blnLocalIsCurrent = VersionUpToDate(strNetworkFolder & "\" & strFe, strDeployFolder & "\" & strFe)
	If blnLocalIsCurrent = False Then
		strMsg = "MyApp needs to be updated with the current version. Would you like to do that now?"
		varRetVal = MsgBox(strMsg, vbYesNo+vbQuestion, "Update?")
		If varRetVal = vbYes Then
			objFso.CopyFile strNetworkFolder & "\" & strFe, strDeployFolder & "\" & strFe
			MsgBox "MyApp was updated.", vbInformation, "Updated."
		End If
	End If
End If

Sub MakeDesktopShortcut(strPath)
	'Make a desktop shortcut
	Dim objShell, objShortcut, strDesktop
	Set objShell = CreateObject("WScript.shell")
	strDesktop = objShell.SpecialFolders("Desktop")
	Set objShortcut = objShell.CreateShortcut(strDesktop & "\MyApp.lnk")
	objShortcut.TargetPath = strPath
	objShortcut.Save
	Set objShell = Nothing
End Sub

Sub DoFullDeploy(objFso, strPathFrom, strPathTo, strFe, blnFolderExists)
	'Do a full deployment
	Dim strMsg, varRetVal
	strMsg = "The application MyApp needs to be deployed to this computer"
	strMsg = strMsg & vbCrLf & vbCrlf
	strMsg = strMsg & "Do you want to proceed with deployment?"
	varRetVal = MsgBox(strMsg, vbYesNo+vbQuestion, "Deploy MyApp?")
	If varRetVal = vbYes Then
		If blnFolderExists = False Then objFso.CreateFolder strDeployFolder
		objFso.CopyFile strPathFrom & "\" & strFe, strPathTo & "\" & strFe
		MakeDesktopShortcut strPathTo & "\" & strFe
		MsgBox "MyApp has been deployed.", vbInformation, "Deployment"
	End If
End Sub

Function GetVersion(strFile)
	'Return the version of a front end file
	Dim app, wks, db, rst, strVersion
	Set app = CreateObject("Access.Application")
	Set wks = app.DBEngine(0)
	Set db = wks.OpenDatabase(strFile)
	Set rst = db.OpenRecordset("Select SettingValue From tblFeSettings Where SettingName = 'Version'")
	strVersion = "" & rst("SettingValue")
	rst.Close
	Set rst = Nothing
	Set db = Nothing
	Set wks = Nothing
	app.Quit
GetVersion = strVersion
End Function


Function VersionUpToDate(strNetworkCopy, strLocalCopy)
	'Compares the two versions
	Dim strNetworkVersion, strLocalVersion, blnUpToDate
	blnUpToDate = False
	strNetworkVersion = GetVersion(strNetworkCopy)
	strLocalVersion = GetVersion(strLocalCopy)
	If strLocalVersion = strNetworkVersion Then
		blnUpToDate = True
	End If
VersionUpToDate = blnUpToDate
End Function




