Front End Auto-Update

Status
Not open for further replies.

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 09:40
Joined
Oct 17, 2012
Messages
3,276
We've seen a number of requests lately about automatically distributing database front end files after a new version is released. This is a modified version of code taken elsewhere on the web; I did not write the vast majority of it, only making a couple updates (mainly to keep the code from deleting the front-end if the file is run with no network connection).

Edit: I have been told the original code is by Bob Larson, just to give credit where credit is due.

To make it work, you need:

  1. A table in the front end called tbl-fe_version, with a field fe_version_number.
  2. A table linked into the front end called tbl-version_fe_master, with a field fe_version_number.
  3. A table linked into the front end called tbl-version_master_location, with a field s_masterlocation.
Tables 2 and 3 can be in either the back end or in a completely separate file. You can also use different names for the tables and/or fields, as long as you update the correct references in the code.

The way it works is that the tool first checks to see if the master file is the one being executed by comparing the path of the currently running version of your application against the master location from 3 above. If a local copy is being run instead, it then compares version numbers. If they do not match, it writes a batch file that will delete the local copy of the tool, then copy the master copy from the folder at 3 above, and then restart your application.

Word of warning - make absolutely sure your master copy has the same version number as is found in 2, or you will wind up stuck in a delete/update loop.

Anyway, here's the code for the version checker:

Code:
Public Function CheckFrontEnd() As Integer
[COLOR=seagreen]' ************************************************************[/COLOR]
[COLOR=seagreen]' Created by       : Scott L Prince[/COLOR]
[COLOR=seagreen]' Parameters       : None[/COLOR]
[COLOR=seagreen]' Result           : Determines if backend can be reached, and if front end is the current version.[/COLOR]
[COLOR=seagreen]' Returns          : 0 - Misc Error[/COLOR]
[COLOR=seagreen]'                  : 1 - No current version found in Version Manager file[/COLOR]
[COLOR=seagreen]'                  : 2 - Front end being run from master location[/COLOR]
[COLOR=seagreen]'                  : 3 - Master file path not found in Version Manager file[/COLOR]
[COLOR=seagreen]'                  : 999 - Front end current[/COLOR]
[COLOR=seagreen]' Date             : 5-30-14[/COLOR]
[COLOR=seagreen]' Remarks          : Based on previously-existing code by Bob Larson posted at StackOverflow[/COLOR]
[COLOR=seagreen]' Changes          :[/COLOR]
[COLOR=seagreen]' ***************[/COLOR][COLOR=seagreen]*********************************************[/COLOR]
Dim FrontEndVersion As String               [COLOR=seagreen]'Front end version number[/COLOR]
Dim MasterVersion As String                 [COLOR=seagreen]'Master version number[/COLOR]
Dim MasterPath As String                    [COLOR=seagreen]'Location of the master FE file[/COLOR]
Dim BatchPath As String                     [COLOR=seagreen]'Location of the batch file that does the actual update[/COLOR]
 
    [COLOR=seagreen]'Determine master version number.[/COLOR]
    MasterVersion = DLookup("fe_version_number", "tbl-version_fe_master")
 
    [COLOR=seagreen]'Determine if the database containing the version information can be accessed.[/COLOR]
    Select Case MasterVersion
        Case ""                             [COLOR=seagreen]'Master version number cannot be found, or backend/version manager is missing.[/COLOR]
 
            CheckFrontEnd = 1
 
        Case Else                           [COLOR=seagreen]'Version data found.[/COLOR]
 
            [COLOR=seagreen]'Look up the path for the master file location.[/COLOR]
            MasterPath = DLookup("s_masterlocation", "tbl-version_master_location")
 
            [COLOR=seagreen]'Determine if the master file is being run rather than a local copy.[/COLOR]
            If Nz(MasterPath, "") = "" Then
 
                [COLOR=seagreen]'No master path was found.  Return error value.[/COLOR]
                CheckFrontEnd = 3
 
            ElseIf MasterPath = CurrentProject.Path Then
 
                [COLOR=seagreen]'The actual master file is the one being executed.[/COLOR]
                CheckFrontEnd = 2
 
            Else
 
[COLOR=seagreen]              'Master file path found and is not being run.  Determine the version number of the active front end.[/COLOR]
                FrontEndVersion = DLookup("fe_version_number", "tbl-fe_version")
 
[COLOR=seagreen]              'Compare the version number in the front end to the master version number.[/COLOR]
                Select Case (FrontEndVersion = MasterVersion)
 
                    Case True           [COLOR=seagreen]'Version numbers match.[/COLOR]
 
                        [COLOR=seagreen]'Return "OKAY" result.[/COLOR]
                        CheckFrontEnd = 999
 
                    Case False         [COLOR=seagreen]'Version numbers do not match.[/COLOR]
 
[COLOR=seagreen]                      'Create the path for the batch file used to update the front end.[/COLOR]
                        BatchPath = CurrentProject.Path & "\UpdateDbFE.cmd"
 
                        [COLOR=seagreen]'Check for an already-existing BatchPath, and kill it if it exists.[/COLOR]
                        If Dir(BatchPath) <> "" Then Kill BatchPath
 
                        [COLOR=seagreen]'Notify the user that the application will update.[/COLOR]
                        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
 
 [COLOR=seagreen]                       'Execute 'UpdateFrontEnd'.[/COLOR]
                        UpdateFrontEnd CurrentProject.Path & "\" & CurrentProject.Name, MasterPath
 
                End Select
            End If
    End Select
 
End Function

And this is the code for the actual update program. It should be in the same module as the version checking program. It has been tightened up slightly from the original, and reliance on module-level declarations has been removed. The batch file has also been cleaned up.

Code:
[COLOR=black]Private Sub UpdateFrontEnd(ByVal LocalFilePath As String, _[/COLOR]
[COLOR=black]                 ByVal MasterFileFolder As String)[/COLOR]
 
Dim BatchFile As String
Dim MasterFilePath As String
Dim Restart As String
 
    [COLOR=seagreen]'Set the file name and location for the file to copy[/COLOR]
    MasterFilePath = MasterFileFolder & "\" & CurrentProject.Name
    [COLOR=seagreen]'Set the file name of the batch file to create[/COLOR]
    BatchFile = CurrentProject.Path & "\UpdateDbFE.cmd"
    [COLOR=seagreen]'Set the restart file name[/COLOR]
    Restart = """" & LocalFilePath & """"
 
[COLOR=seagreen]'Create the batch file[/COLOR]
    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
 
[COLOR=seagreen]  'Run the batch file[/COLOR]
    Shell BatchFile
 
[COLOR=seagreen]  'Close the current application so batch file can execute.[/COLOR]
    DoCmd.Quit
End Sub
 
Last edited:
Thank you for posting th coding, this just what i need for my DB, i am some what new to VBA coding and i am not sure about implamenting this module in my DB i have made the table and all of that. it isn't working for me and i am wondering if you would have any ideas as to what i might have missed. i copyied the coding built the tables and put in the version numbers.
 
We've seen a number of requests lately about automatically distributing database front end files after a new version is released. This is a modified version of code taken elsewhere on the web; I did not write the vast majority of it, only making a couple updates (mainly to keep the code from deleting the front-end if the file is run with no network connection).

Edit: I have been told the original code is by Bob Larson, just to give credit where credit is due.

To make it work, you need:

  1. A table in the front end called tbl-fe_version, with a field fe_version_number.
  2. A table linked into the front end called tbl-version_fe_master, with a field fe_version_number.
  3. A table linked into the front end called tbl-version_master_location, with a field s_masterlocation.
Tables 2 and 3 can be in either the back end or in a completely separate file. You can also use different names for the tables and/or fields, as long as you update the correct references in the code.

The way it works is that the tool first checks to see if the master file is the one being executed by comparing the path of the currently running version of your application against the master location from 3 above. If a local copy is being run instead, it then compares version numbers. If they do not match, it writes a batch file that will delete the local copy of the tool, then copy the master copy from the folder at 3 above, and then restart your application.

Word of warning - make absolutely sure your master copy has the same version number as is found in 2, or you will wind up stuck in a delete/update loop.

Anyway, here's the code for the version checker:

Code:
Public Function CheckFrontEnd() As Integer
[COLOR=seagreen]' ************************************************************[/COLOR]
[COLOR=seagreen]' Created by       : Scott L Prince[/COLOR]
[COLOR=seagreen]' Parameters       : None[/COLOR]
[COLOR=seagreen]' Result           : Determines if backend can be reached, and if front end is the current version.[/COLOR]
[COLOR=seagreen]' Returns          : 0 - Misc Error[/COLOR]
[COLOR=seagreen]'                  : 1 - No current version found in Version Manager file[/COLOR]
[COLOR=seagreen]'                  : 2 - Front end being run from master location[/COLOR]
[COLOR=seagreen]'                  : 3 - Master file path not found in Version Manager file[/COLOR]
[COLOR=seagreen]'                  : 999 - Front end current[/COLOR]
[COLOR=seagreen]' Date             : 5-30-14[/COLOR]
[COLOR=seagreen]' Remarks          : Based on previously-existing code by Bob Larson posted at StackOverflow[/COLOR]
[COLOR=seagreen]' Changes          :[/COLOR]
[COLOR=seagreen]' ***************[/COLOR][COLOR=seagreen]*********************************************[/COLOR]
Dim FrontEndVersion As String               [COLOR=seagreen]'Front end version number[/COLOR]
Dim MasterVersion As String                 [COLOR=seagreen]'Master version number[/COLOR]
Dim MasterPath As String                    [COLOR=seagreen]'Location of the master FE file[/COLOR]
Dim BatchPath As String                     [COLOR=seagreen]'Location of the batch file that does the actual update[/COLOR]
 
    [COLOR=seagreen]'Determine master version number.[/COLOR]
    MasterVersion = DLookup("fe_version_number", "tbl-version_fe_master")
 
    [COLOR=seagreen]'Determine if the database containing the version information can be accessed.[/COLOR]
    Select Case MasterVersion
        Case ""                             [COLOR=seagreen]'Master version number cannot be found, or backend/version manager is missing.[/COLOR]
 
            CheckFrontEnd = 1
 
        Case Else                           [COLOR=seagreen]'Version data found.[/COLOR]
 
            [COLOR=seagreen]'Look up the path for the master file location.[/COLOR]
            MasterPath = DLookup("s_masterlocation", "tbl-version_master_location")
 
            [COLOR=seagreen]'Determine if the master file is being run rather than a local copy.[/COLOR]
            If Nz(MasterPath, "") = "" Then
 
                [COLOR=seagreen]'No master path was found.  Return error value.[/COLOR]
                CheckFrontEnd = 3
 
            ElseIf MasterPath = CurrentProject.Path Then
 
                [COLOR=seagreen]'The actual master file is the one being executed.[/COLOR]
                CheckFrontEnd = 2
 
            Else
 
[COLOR=seagreen]              'Master file path found and is not being run.  Determine the version number of the active front end.[/COLOR]
                FrontEndVersion = DLookup("fe_version_number", "tbl-fe_version")
 
[COLOR=seagreen]              'Compare the version number in the front end to the master version number.[/COLOR]
                Select Case (FrontEndVersion = MasterVersion)
 
                    Case True           [COLOR=seagreen]'Version numbers match.[/COLOR]
 
                        [COLOR=seagreen]'Return "OKAY" result.[/COLOR]
                        CheckFrontEnd = 999
 
                    Case False         [COLOR=seagreen]'Version numbers do not match.[/COLOR]
 
[COLOR=seagreen]                      'Create the path for the batch file used to update the front end.[/COLOR]
                        BatchPath = CurrentProject.Path & "\UpdateDbFE.cmd"
 
                        [COLOR=seagreen]'Check for an already-existing BatchPath, and kill it if it exists.[/COLOR]
                        If Dir(BatchPath) <> "" Then Kill BatchPath
 
                        [COLOR=seagreen]'Notify the user that the application will update.[/COLOR]
                        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
 
 [COLOR=seagreen]                       'Execute 'UpdateFrontEnd'.[/COLOR]
                        UpdateFrontEnd CurrentProject.Path & "\" & CurrentProject.Name, MasterPath
 
                End Select
            End If
    End Select
 
End Function

And this is the code for the actual update program. It should be in the same module as the version checking program. It has been tightened up slightly from the original, and reliance on module-level declarations has been removed. The batch file has also been cleaned up.

Code:
[COLOR=black]Private Sub UpdateFrontEnd(ByVal LocalFilePath As String, _[/COLOR]
[COLOR=black]                 ByVal MasterFileFolder As String)[/COLOR]
 
Dim BatchFile As String
Dim MasterFilePath As String
Dim Restart As String
 
    [COLOR=seagreen]'Set the file name and location for the file to copy[/COLOR]
    MasterFilePath = MasterFileFolder & "\" & CurrentProject.Name
    [COLOR=seagreen]'Set the file name of the batch file to create[/COLOR]
    BatchFile = CurrentProject.Path & "\UpdateDbFE.cmd"
    [COLOR=seagreen]'Set the restart file name[/COLOR]
    Restart = """" & LocalFilePath & """"
 
[COLOR=seagreen]'Create the batch file[/COLOR]
    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
 
[COLOR=seagreen]  'Run the batch file[/COLOR]
    Shell BatchFile
 
[COLOR=seagreen]  'Close the current application so batch file can execute.[/COLOR]
    DoCmd.Quit
End Sub
Hello,

I have a question. i am currently building a multi user Access application at work. You code is perfect for that. Can I use this as part of a Business Application?

Regards,

Arka
 
Hi Sean!
I solved this problem a long time ago using this very simple solution: a scheduled job was run daily, the plant was operating 24/7, at 12:12 every day. It was checking on the server if a new version was available and if so, a copy to local PC was made. On my PC, I had another SJ running at 1:30 deleting the server version of the apps (almost 2000 objects).

Good luck, JLCantara.
 
Hello Frothingslosh:
I added your code in a module and compile it. There is a

"COMPILE ERROR" - Sub or function not defined.

Kindly upload a small sample of your version checker (any version up to Access 2013 can be uploaded here).

I'm the second person requesting your sample due to error. Another person (Sean75db) who posted earlier in the thread also asked for a sample. It will be appreciated if you would upload a small sample. Thank you.
 
Addionally, the compile error highlighted "UpdateFrontEnd "
This means that "UpdateFrontEnd " is not defined in your module.
Thanks in advance.
 
Has this been proven with MS Access Runtime on the Front Ends?
 
This is a great module that works wonderful, but I wanted to let people know you can do the version checking without using VBA, and simply have an Updater application that runs the VBA to delete your local copy and download the fresh version off the server.

I use a table called AppConstants on the server's backend that has two columns: ConstantTitle and ConstantValue. One of the rows has ConstantTitle set to "AppVersion" and ConstantValue set to the version number.

Then I have a field with visibility set to False on my main form called VersionNo, and I set this field's value to ="VersionNumber" (where VersionNumber is the actual version number, e.g. ="1.25"). On the Main Form's OnLoad event, I have a macro that runs a DLookup in an IF command:

if DLookUp("[ConstantValue]", "tblAdmin", "[ConstantTitle]='AppVersion'")<>[Forms]![frmMain]![VersionNo] Then RunCode OpenUpdater()
Quit Access
End If

The code for OpenUpdater:
Code:
Function OpenUpdater()  'This sets the name of the code to call later
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("C:\$Data\MyUpdater.accde")  'Starts up this file
accapp.Visible = True
End Function

What it's doing: The macro checks the value of the VersionNumber in the table on the server. When I update the app copy on the server, I set a new version number in here and set my app copy's VersionNo field to the same number. When you're running the old version, your app sees that the version numbers don't match, and then it executes the Macro's 'Then' commands: it runs the OpenUpdater code and shuts itself off.

The OpenUpdater code simply starts the MyUpdater.accde program, which is by default installed on the user's PC along with the application itself. The OpenUpdater program executes the following code:

Code:
DoCmd.ShowToolbar "Ribbon", acToolbarNo

'Copy the new version to the C drive
Dim SourceFile, DestinationFile As String
    SourceFile = "Z:\Server\MyProgram.accde"   'Where to get the fresh copy
    DestinationFile = "C:\$Data\MyProgram.accde"   'Where to put it
    With CreateObject("Scripting.FileSystemObject")
    .copyfile SourceFile, DestinationFile, True    'This line does the acual copy and paste
End With

'Reopen MyProgram
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("C:\$Data\MyProgram.accde")
accapp.Visible = True
End Function

This Function is called in a Macro within MyUpdater, and the command just after the RunCode in this Macro is QuitAccess, which shuts off the Updater.

So my main program, when you open the main form, checks the version number on the server. If they're different, the main program starts the updater and then shuts itself down. The updater copies the fresh version off the server and pastes it in the correct place on the C drive, then starts up the program and shuts itself down.

From the end-user's perspective, the program starts, immediately quits, and then starts again a second or so later and now it's updated. It works awesome.
 
I have a question about the 6-9-2014 post by Frothingslosh. Where would I place the CheckFrontEnd() function for this to run when a user opens the database?

Thank you
 
Hello

i know this is an old thread but i am new to this forum. I am trying to get the FE update to work by "Frothingslosh" but when i run it the message i get is "Cannot find master file", something like that anyway. I understand how to create tables and fields, but unsure how to have a table in the FE that is not linked to the the BE. and also what data needs to go in to the three tables. A simplified example would be great if at all possible.
 
Great bit of code.

Since my users will she the front end in a variety of places on their PC, is there a way to grab the current path of the outdated front end before closing it, and then inserting that path into the copy statement, so that the new front end is chipped to the same location the user choose to put his original front end?

Cheers

Zane
 
Hi Guys,

sorry for redigging old topic, but i have to ask

which is by default installed on the user's PC along with the application itself.

what does it mean? What mechanism are you using?

Best,
Jacek
 
I have just approved 8 posts in this thread, some of which had been buried for over 2 years. Posting to trigger email notifications
 
Oh, dear, so many responses all at once.

Hello,

I have a question. i am currently building a multi user Access application at work. You code is perfect for that. Can I use this as part of a Business Application?

Regards,

Arka

This was posted for anyone to use, so feel free. I would ask that anyone using this credit Bob Larson in the notes.

Hello Frothingslosh:
I added your code in a module and compile it. There is a

"COMPILE ERROR" - Sub or function not defined.

Kindly upload a small sample of your version checker (any version up to Access 2013 can be uploaded here).

I'm the second person requesting your sample due to error. Another person (Sean75db) who posted earlier in the thread also asked for a sample. It will be appreciated if you would upload a small sample. Thank you.

I don't use this where I work - we use batch files to force a download every time the user starts the app instead - but this code was literally cut and pasted from a working database I had on my previous PC.

As to 'UpdateFrontEnd' not being defined in my module, I don't see how that is remotely possible, seeing as it's the name of the procedure in the second code window. If you try to compile and you're told there's no UpdateFrontEnd, please come back to this post and grab BOTH procedures, not just the first one. :p

Has this been proven with MS Access Runtime on the Front Ends?

Yes

I have a question about the 6-9-2014 post by Frothingslosh. Where would I place the CheckFrontEnd() function for this to run when a user opens the database?

Thank you

Make a startup procedure that is called via the macro AutoExec. Make this the first thing that procedure does.

Hello

i know this is an old thread but i am new to this forum. I am trying to get the FE update to work by "Frothingslosh" but when i run it the message i get is "Cannot find master file", something like that anyway. I understand how to create tables and fields, but unsure how to have a table in the FE that is not linked to the the BE. and also what data needs to go in to the three tables. A simplified example would be great if at all possible.

tbl-fe_version must be included in the front end. It contains the field fe_version_number, which is the version number for the front end.

tbl-version_fe_master is saved in the same location as the master copy but in a separate database (the name doesn't really matter), and you link it to the front end. It ALSO has a field fe_version_number, and it contains whatever the current MASTER version number is.

Finally, there is a table tbl-version_master_location. It can be in the same database as the master version number (that's where I'd put it), or it can be in the regular backend. Either way, it must ALSO be linked to the front end. The table contains the field s_masterlocation, which simply stores the full path (but not the name) for the master front end location.

Those are really all that's needed to make this work, but FOR THE LOVE OF GOD, when you update a new front end version, make sure to match the front end version with the master version or your users will wind up in an infinite update loop.

Great bit of code.

Since my users will she the front end in a variety of places on their PC, is there a way to grab the current path of the outdated front end before closing it, and then inserting that path into the copy statement, so that the new front end is chipped to the same location the user choose to put his original front end?

Cheers

Zane

It already does this.

Hi Guys,

sorry for redigging old topic, but i have to ask



what does it mean? What mechanism are you using?

Best,
Jacek

I think Tuck was just saying that he installs MyUpdater.accde (which just autoruns the code he provided) at the same time and into the same directory as whatever application he is installing.
 
Last edited:
We've seen a number of requests lately about automatically distributing database front end files after a new version is released. This is a modified version of code taken elsewhere on the web; I did not write the vast majority of it, only making a couple updates (mainly to keep the code from deleting the front-end if the file is run with no network connection).

Frothingslosh,

I have implemented this code in my database it works well other than one little snag.

I notice that it leaves a batch file on my desktop (where I have my front end app located) after I open it up and let it do the update thing.

The bad part is I just happened to click on it while my front end was open and it tried to do the delete/download etc process again and that rendered the front end useless and no longer functioned.

do you know of a way to make that code clean up after itself?

I put your code in a module and called it from my login form to check before anyone can login since there are different security levels and to not have to put code in every home screen.

Thank you very much in advance.
 
Sure, just take the first two lines of code in the FALSE condition (setting BatchPath and killing any existing batch file) of the version number check, and run them at the very start of the procedure.
 
Guys, I'me developing a networked database, split front end (installed Locally) & backend on Server. Downloaded & installed the BTAB code & installation instructions. Install went as stated, but I cannot link to the "Tbl-Version_FE_Master" as described in the documentation. When I browse to the file location outside Access I can see the BE files including the newly made version # table. But from within Access I cannot, upon selecting link external data, browse to the file, although I do see all the BE files that I previously separated. That is, I cannot set the link. I have copied the instruction line below. Any ideas? AS usual appreciate the help.

"6. From the FRONT-END, you MUST set a link to the 'tbl-version_fe_master' in your backend database. If you do not, the process will not work. To link, click File / Get External Data / Link Tables and then browse to the back-end database. Select it and click LINK button. Find 'tbl-version_fe_master.' select it and click OK."
 
@TJHill
You posted to a moderated area and your post got lost in cyberspace.
Please see the sticky thread about reporting your own post.

In this case you might do better to create a new thread with your question then provide a link back to this thread.

Good luck
 
Status
Not open for further replies.

Users who are viewing this thread

Back
Top Bottom