Hi I am new to access and I came across an auto updater. I cannot get it to work completely; can anyone see my issue? Thanks
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:
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:
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.
I have attached the updater which works when I manually run it but I cant get it to run automatically
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:
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:
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.
I have attached the updater which works when I manually run it but I cant get it to run automatically