I wrote a batch file for the first time. Hoping for some feedback. 
This retrieves a copy of the latest frontend database and copies it to the user's C drive basically. I've tested it a fair amount in different scenarios and it seems to work.
The batch file is stored on a network drive. Users start it from a shortcut on their machine. I have another shorter batch file that just launches the local frontend copy. Shortcuts to both batch files are copied onto the user's machine if they're not already there. These shortcuts can also be pinned to the user's taskbar since I made them with "cmd /c".
(This updater batch file can also function as a first time installer, although I do have to manually add the new folder as a trusted location in Access after running the batch file.)
([...] in file paths are redactions for confidentiality reasons)

This retrieves a copy of the latest frontend database and copies it to the user's C drive basically. I've tested it a fair amount in different scenarios and it seems to work.
The batch file is stored on a network drive. Users start it from a shortcut on their machine. I have another shorter batch file that just launches the local frontend copy. Shortcuts to both batch files are copied onto the user's machine if they're not already there. These shortcuts can also be pinned to the user's taskbar since I made them with "cmd /c".
(This updater batch file can also function as a first time installer, although I do have to manually add the new folder as a trusted location in Access after running the batch file.)
([...] in file paths are redactions for confidentiality reasons)
Code:
@echo off
REM Change mblVersionNumber to current MBL frontend version number in format. Must match exactly version number used in the Frontend filename stored on Z drive
set mblVersionNumber=v25.5
REM Checks for network drive connection. If not connected, prompts user and closes
if not exist "\\[...]\Data" (
echo Please connect to Z drive first!
echo Window will close after 5 seconds...
timeout /t 5 /nobreak >nul
EXIT
)
REM Checks if Access is open. Closes Access if open
tasklist /fi "ImageName eq MSAccess.exe" /fo csv 2>NUL | find /I "MSAccess.exe">NUL
if "%ERRORLEVEL%"=="0" (
echo Closing Access.
taskkill /im MSAccess.exe
echo Please wait 10 seconds...
timeout /t 10 /nobreak >nul
) else (
echo Access is not open
)
REM Creates MBL Database folder on user's computer if not found
if not exist "%userprofile%\MBL Database" (
echo MBL folder does not exist. Creating MBL Database Folder...
md "%userprofile%\MBL Database"
) else (
echo MBL Database folder exists.
)
REM Deletes any and all frontend copies on user's machine
del /q "%userprofile%\MBL Database\MBL Frontend*.accdb"
REM Copies current frontend database to user's machine
robocopy "\\[...]\Data\Current\[...]\Census Database and Tools" "%userprofile%\MBL Database" "MBL Frontend %mblVersionNumber%.accdb" /mt /z
if not exist "%userprofile%\MBL Database\MBL Database Updater Shortcut.lnk" (
robocopy "\\[...]\Data\Current\[...]\Census Database and Tools\Updater" "%userprofile%\MBL Database" "MBL Database Updater Shortcut.lnk" /mt /z
)
if not exist "%userprofile%\MBL Database\MBL Frontend Launcher Shortcut.lnk" (
robocopy "\\[...]\Data\Current\[...]\Census Database and Tools\Launcher" "%userprofile%\MBL Database" "MBL Frontend Launcher Shortcut.lnk" /mt /z
)
REM Changes current directory to MBL Database folder on user's machine because apparently ren doesn't work with %userprofile%
cd /D "%userprofile%\MBL Database"
REM Removes version number from local copy of frontend. This is done to prevent breaking any shortcuts to the local frontend copy the user may have made previously
ren "MBL Frontend *.accdb" "MBL Frontend.accdb"
set mblLocalPath="%userprofile%\MBL Database\MBL Frontend.accdb"
REM Starts Access with local copy of frontend in runtime mode
echo Launching MBL Access database
Start MSAccess.exe /runtime %mblLocalPath%
EXIT
Last edited: