Auto Updater (1 Viewer)

ty939

New member
Local time
Today, 15:05
Joined
Feb 14, 2019
Messages
9
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
 

Attachments

  • MyUpdater.accdb
    408 KB · Views: 292

essaytee

Need a good one-liner.
Local time
Tomorrow, 08:05
Joined
Oct 20, 2008
Messages
512
I can't check your file right now but why don't you have the users start your application from the updater file/script, problem solved.


FWIW, I tackle this in a slightly different way. Users start the application directly, in the start-up routine, a version check is made, if there is a new version, then run a batch file and very next line the application is closed/exited. The batch/vbscript continues, I have it wait for 6-10 seconds before it starts to copy files from the server to the users folder and then restart the application. This has worked for me for so many years.


Macros v VBA, I'm so use to VBA that I can't comment on Macros as I don't use them, except for Autoexec.
 

ty939

New member
Local time
Today, 15:05
Joined
Feb 14, 2019
Messages
9
Can you help me do this? I am extremely new at access
 

ty939

New member
Local time
Today, 15:05
Joined
Feb 14, 2019
Messages
9
I tried what was suggested but it didn't work for me

I have all three stripped down here
 

Attachments

  • Updatercopy.accdb
    512 KB · Views: 277
  • UpdaterMaster.accdb
    448 KB · Views: 249
  • FMRU_be.accdb
    752 KB · Views: 287
Last edited:

June7

AWF VIP
Local time
Today, 14:05
Joined
Mar 9, 2014
Messages
5,470
"Didn't work" means what - error message, wrong result, nothing happens?

To auto run your code, options:

1. form load event calls the macro or with my code which does not use macro all VBA code is in form load event, either way, set db option to open that form by default - this was described in the other thread

2. AutoExec macro, rename your Update macro to AutoExec - Access is designed to look for AutoExec macro and if found, run it
 
Last edited:

ty939

New member
Local time
Today, 15:05
Joined
Feb 14, 2019
Messages
9
"Didn't work" means what - error message, wrong result, nothing happens?

To auto run your code, options:

1. form load event calls the macro or with my code which does not use macro all VBA code is in form load event, either way, set db option to open that form by default - this was described in the other thread

2. AutoExec macro, rename your Update macro to AutoExec - Access is designed to look for AutoExec macro and if found, run it

Nothing happens, It works when I run the updater macro but its not doing it via dlookup
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:05
Joined
Sep 21, 2011
Messages
14,260
Get the value first from DLookup and then compare that to Form value.
 

Cronk

Registered User.
Local time
Tomorrow, 08:05
Joined
Jul 4, 2013
Messages
2,772
Re #5
I have all three stripped down here


You've done a good job stripping the 3 databases (why 3?) that the relevant code is not there.
 

ty939

New member
Local time
Today, 15:05
Joined
Feb 14, 2019
Messages
9
Re #5



You've done a good job stripping the 3 databases (why 3?) that the relevant code is not there.


The database had confidential information and was too big to put on here. I created something really quick with the code in it. I think that the dlookup is the issue here because the copy part works. In the dlookup it has a tblAdmin but he doesn't mention that when explaining the directions. I instead used the table which was AppsConstants. Could it be that?
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 08:05
Joined
Oct 20, 2008
Messages
512
OP, did you get the program to start automatically, as you haven't confirmed this. June7 gave you the 'Autoexec' info.

Your initial post #1, I misread it slightly, in that I thought you wrote the update routines in that references were made to 'I did this....." strewn throughout the post. I see now that is what you copied and pasted (no problem with that, it's me reading it out of context, easy to do when speed reading). It was for this reason in my first comment I mentioned an alternative approach believing you had a handle on things.

So point one, did you get it to run automatically? I'm not asking did the actual code work, that's step two, three, four etc.
 

Users who are viewing this thread

Top Bottom