Deploying and updating Front End Database Applications In the preferred multi-user database set up, the database is split. The tables are contained in what is referred to as the Back End (BE). This file lives in a shared folder to which all users have read/write/edit/delete permissions. This allows each user's instance of Access to create, update and close the record locking file. All other objects (forms, reports, macros, queries, code modules and possibly local static or personal preference tables) are kept in a separate database file called the Front End (FE). Each user has his own copy of the FE on his local hard drive. The FE links to the tables in the BE. Allowing more than one person to access the FE is a big Bozo No-No. It leads to database corruption and dramatically slows down performance. Got that? Good! So now I bet you are saying, "Oh, sure! I've got 132 users, and FE design changes happen almost every week. New reports are added, more functionality is required and who knows what else they want. How can I possibly keep up on deploying new FEs to my users? I don't even work the same shift as some of them!" Not to worry, Bunky! There are several simple ways to make sure your users always have the version of the FE. One way is to use Tony Toews' Auto FE Updater. You can find it at http://www.granite.ab.ca/access/autofe.htm. But I prefer my own way of doing things so I wrote a VBScript that does all the work. In fact, you don't even have to deploy the FE at all. Just give each user a desktop shortcut to the VBS file once. They double-click the shortcut and all the necessary files are downloaded right to their hard drives. When you make a change to the FE all you do is copy it to the shared folder, change the date in the name of a text file whose only purpose in life is to act as the version identifier and change that text file's name in the VBScript. Is that simple enough? But I'm getting ahead of myself. Click here to see a sample and we'll get started breaking this all down into digestible pieces. The script has a two-fold purpose in life. Actually, three if you count making your life easier. The first is to do the initial FE "installation". The second is to check for updated versions download them and swap out the old version. At the very top of the sample, you'll see the script's header. Use this to document what's going on in case you get hit by a bus and someone else has to take over. You might even want to include this article's URL. I wouldn't mind a bit. The script contains a short list of instructions, but I'll go into it in detail. You'll probably notice right away that VBScript is a lot like VBA so it should be pretty easy to take the plunge and start writing your own scripts. I regularly use Access's VBA editor to write my scripts. They sometimes have to be changed a bit once you put the code into a .vbs file, but why not take advantage of the editor's features? When you are finished with your script copy it into NotePad or any other text editor. Save it with a vbs extension. NotePad will add a txt extension unless you select All files (*.*) as the file type. If that hppens fix it in Windows Explorer. Note the list of constants on the next lines. These are all global to the script which saves a lot of time when it comes to editing the values. Note also that I never declare the data types. Now you VBA coders are saying, "That is just plain sloppy coding. Shame on you!" To which I say, Ha! You can't declare data types in VBScript. Everything is a variant. As I mentioned, VBScript is a lot like VBA, and some differences are sneaky ones. I use Option Explicit at the top of the code so all variables must be declared. VBScript is tough enough to debug without having to fight typos, too. The Constants: cTXTFILE is the text file that the script uses to determine the latest version. More on that to follow. cSVRPATH is the path to the server where the FE file lives. It's also where you will put all the dependent files you need like the database's icon, any DLLs you use, images, etc. cLOCALPATH is the path to the user's copy of the FE. It will also be the path for those other files mentioned above. cFE is the name of your FE (duh). cZIP is the name of the zip file in which you put everything so the download doesn't put your users to sleep while they wait for it to finish. Some of the places in which I've worked have T1 connections to their outer lying offices. Downloading a 2 mg file is far better that a 20 mg file. cICON is the name of your application's icon file for the desktop shortcut to launch the script. cSCRIPTNAME is the name of your script. You're probably wondering why you would need the name of the script within the code. Be patient. You'll find out. cSCNAME is the name of the local shortcut to open the FE. cANIGIF is the name of the animated gif file that will be used so the user doesn't think the whole process hung. Remember the T1 cable I told you about? cAPPNAME is the user-friendly name of the application and will be used for the desktop shortcut. It is important to remember that if your paths or file names contain spaces, there are places where you will have to use double-double quotes (a string of four double quotes) or Chr(34) on both ends when using the constant. Chr(34) is a double-quote and when concatenated to a string it is read as a literal. The double quote thing isn't necessary with the FileSystemObject, but it is with the shortcut Target and Aruguments. I've tried to find all the necessary places and do it for you, but if you get a "bad file" or "file not found" error that will probably be why. And the only way you will find out is if you comment out the "On Error Resume Next" lines where it looks like it might be a problem and run the script until it errors out. So from all that, you can guess that I never put spaces in my folder or file names. The only place I get overruled is with the Program Files folder. The next three globals are variables used throughout the script. I'll go over them as we come to them. Before we start going through the code, I need to tell you a couple things. There is only one VBScript file. It lives on the server. That means you only have to edit one script. The user has a desktop shortcut that launches the script. As I said earlier, the script does all the deployment tasks for you. Scroll down to the very bottom of the script and you will see the starting point. Since we have several procedures, it's only fair that we have to tell the script where to start. Just because it's a common practice in other languages to use "main" as the name of the first procedure, that's what I called mine, but you can call it whatever you want. Let's look at what is going on in main. This procedure calls several other procedures in the proper order. Main first calls a procedure to make a splash screen. The splash screen gives the users something to look at and let's them know that the application is going to open. If you don't do that, and your application takes a while to download, Joe Accountant might think nothing is happening and click the desktop shortcut again and again and again... Hopping up to the function named "SplashBox" at the top, we see an Internet Explorer object is created. This is what your user will see:
 I used Tom Lavedas's code to create an IE window because there is no native form in Windows to use in this way as far as I know. You'll spot a few constants in this function: The application name is used on the window, the server path and animated gif path are used to display the gif so the user can see something is happening. Now we get to the workings of this script. A WSHShell object is created to be used later. A FileSystemObject is also created. This is what we will use to do our file stuff. Its first job is to check for the text file that is used to determine if the user has the latest version. This is done in a very simple way. The text file has a date suffix added to it. In this example, the text file is named "ProjectMgmt_feV20080815.txt". The date is yyyymmdd. Use whatever format you are accustomed to. This file name says August 8, 2008 was when the last version of the FE was placed on the server for deployment. If the user had previously downloaded that version, he would have the same text file on his hard drive. A new download probably isn't necessary, but we check to see if the FE also exists in the folder. It might have been accidentally deleted, or if the user needed a new copy to replace a bad one all that need be done is to delete the FE or the text file. If either file is missing delete the text file. GetDB is called. GetDB checks to see if the folder exists. If not, it creates it using the cLOCPATH constant. Then the text file and the FE zip file are copied from the server. I suppose the text file could be put in the zip file, too, but the file is so small there really is no need to do that especially when you will be renaming it with every version update. Once we have the two files we need to unzip them. I chose to use the built-in file compressor that comes with Windows XP because all my users have XP. The procedure named Unzip is called from GetDB, passing the local folder path and zip file as the first argument and the local path as the second argument. Unzip creates a Shell.Application object and uses its Namespace to handle the files within the zipped folder. It goes through each file and if the file already exists in the local folder it is deleted from that folder and the new one replaces it. I'm not sure if deleting the files is necessary, but I ran into occasional errors when I did not. After the files are unzipped, the zip file is deleted. No use cluttering up someone's hard drive. Maybe you are wondering why I just didn't unzip from the server to the local drive. Remember about the slow network connection? If I could quickly unzip from server to local I wouldn't even need a zip file. The whole point is to speed up the file transfer. Then the temp file that the compressor uses is deleted. Again, this should not be necessary, but I found I was growing a bunch of temp files that were not getting deleted by the system. Almost done! Now we'll make a new local FE shortcut. I did this because you never know if a user upgrades his version of Access. If you left the shortcut that targets Access 12 in the folder and there is an upgrade to 2007 the shortcut will no longer work. If the procedure that makes the new shortcut fails, the user is warned that something is rotten in Denmark and the script cleans up pointers and exits. It would be nice if VBScript used error trapping like VBA, but alas, it does not. Just as there is no "try" for Luke Skywalker, there is no GoTo in VBScript. Next we make a new desktop shortcut. I did this just in case the script has to be moved to a different location. If we let the original script make the change to the target of the shortcut, we can put the new script anywhere we want and eventually delete the original script. Sure, you might miss a few users who rarely use your application, but a few manual changes are better than a hundred, right? As we near the finish line, we run the local shortcut that opens the FE. All that's left after that is to clean up the object pointers and we're done. When you kick this all off you will have to have this minimum list of files in the server folder: 1. The text file with the date suffix in the name. I usually put something like this in the file itself. "Please do not move or delete this file. It is used to determine if you have the latest version of <Your App Name Goes Here>." 2. The zip file that holds your FE and any other files you need the user to have such as DLLs, icon files, images your app might use, etc. 3. The all-powerful VBScript. 4. Your animated gif (if you choose to use one). 5. The desktop shortcut that you give the user (might as well keep it where it is handy). Put your copy of the latest FE in the zip file. Update the date in the text file name. And you're done. While it took me a couple thousand words to explain all the ins and outs of my little updater going from the first install to keeping the latest version at your users' fingertips, hopefully it will make your life a whole lot better by letting the script do your version deployment for you. Heck, you don't even have to be in the office when all this happens. Let me know how it works for you.
-top-
|