Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Preparing Your Database for Use with the Access Runtime Version


Several steps are required to prepare your database for use with the Access runtime version. Although many of these steps are mandatory when distributing your application with the runtime version, they also are good as a general practice when developing a polished application. To prepare your application for use with the Access runtime version, follow these steps:

    Creating the Application


    You must be concerned about several things when designing an application for use with the Access runtime version. Although the following items are niceties in any application, they are a mandatory aspect of developing an application for use with the Access runtime version:

    • Build the application around forms.

    • Build error handling into the application.

    • Build custom menus and toolbars into the application.

    • Set startup options for the application.

    • Properly secure the application.


    Building the Application Around Forms and Menus

    The first step when creating the application with runtime distribution in mind is to build the application around forms and menus. This means that everything in the application needs to be form- and menu-driven. Your application generally should begin by displaying a Main Switchboard, or a startup form with a main menu. The user can then navigate from the Main Switchboard to additional switchboards, such as a Data Entry Switchboard, Reports Switchboard, Maintenance Switchboard, and so on.

    An alternative is to display the most commonly used form when the application launches. Menu and toolbar items are used to navigate to other parts of your application. For example, if the application's main purpose is to maintain membership information for a union, the startup form could be the membership form. Other forms, such as the member payments form, could be accessed via a menu attached to the membership form. This second option is my personal favorite.

    Building Error Handling into the Application

    It is imperative that you build error handling into your application. If an error occurs when someone is using the runtime version of Access and no error handling is in place, an error message is displayed, and the user is instantly returned to the Windows desktop. Therefore, it is crucial that you build error handling into all your routines. Creating a generic error handler to assist you with this task is covered in Chapter 16, "Error Handling: Preparing for the Inevitable."

    Adding Custom Menus and Toolbars

    As mentioned earlier in this chapter, limited versions of the standard Access menus are available under the Access runtime version, but toolbars are not available at all. You therefore must provide your users with whatever menu bar and toolbar functionality the application requires.Chapter 9, "Advanced Form Techniques," you can attach a menu bar to a form using the Menu Bar property of the form. When a specific menu bar is associated with a particular form or report, the menu appears whenever the form or report becomes the active window. It generally is easier to base a form or report's menu on one of the standard Access menus and then add or remove menu items as appropriate.

    You must build each toolbar that you want to use with your application. As covered in Chapter 9, you can specify the toolbar that you want to be visible with your form or report by using the Toolbar property of the form or report. At times, you might prefer to control the toolbars that display by using code. By using this method, you can give the users access to your own toolbars or custom toolbars. Listing 32.1 shows the code placed in the Activate event of the form or report.

    Listing 32.1 Code for the Activate Event

    Private Sub Form_Activate()
    On Error GoTo Err_Form_Activate
    Call ToolBarShow("tbrMainForm", True)
    Me.fsubClients.Requery
    Exit_Form_Activate:
    Exit Sub
    Err_Form_Activate:
    MsgBox Err.Description
    Resume Exit_Form_Activate
    End Sub

    The Activate event of the frmClients form calls a user-defined procedure called ToolBarShow. It passes the ToolBarShow routine two parameters: the name of the toolbar it will affect and a Boolean variable indicating whether you wish to hide or show the specified toolbar. Listing 32.2 shows the ToolBarShow routine.

    Listing 32.2 The ToolBarShow Routine

    Sub ToolBarShow(strToolbar As String, fShow As Boolean)
    DoCmd.ShowToolbar strToolbar, _
    IIf(fShow, acToolbarYes, acToolbarNo)
    DoCmd.ShowToolbar "Form View", _
    IIf(fShow, acToolbarNo, acToolbarWhereApprop)
    End Sub

    The ToolBarShow routine handles both the showing and hiding of custom toolbars. It receives a string and a Boolean variable. The ShowToolbar method, contained in the DoCmd object, makes the toolbars visible or hidden. The command does this by taking the name of the toolbar and a Boolean value (both are passed in as parameters) and toggling the visible property for that toolbar to True for visible or False for hidden, depending on which was passed into the function. If you pass the ToolBarShow routine the string tbrMainForm and the Boolean True, for example, it shows the tbrMainForm toolbar.

    In case the application will run in both the retail and runtime versions of Access, you should ensure that the standard toolbar is hidden when the form is active. The second ShowToolbar method indicates that the Form View toolbar will be hidden if you are displaying the custom toolbar and will be shown, where appropriate, if you are hiding the custom toolbar. The Deactivate event of the form looks like this:

    Private Sub Form_Deactivate()
    Call ToolBarShow("tbrMainForm", False)
    End Sub

    This routine hides the tbrMainForm toolbar and shows the Form View toolbar where appropriate.

    Clearly, it is important that you perform all the menu and toolbar handling required by your application. This ensures that all menu bars and toolbars are available when they should be, and

    only when they should be.

    Setting Startup Options

    Access 2000, Access 2002, and Access 2003 provide you with several startup options that enable you to control what happens to your application when it is loaded. Table 32.2 lists each option in the Startup dialog box.

    Table 32.2. Startup Options

    Option

    Function

    Application Title

    Sets the AppTitle property, which displays a custom title in the application title bar

    Application Icon

    Sets the AppIcon property, which displays a custom icon in the application title bar

    Menu Bar

    Sets the StartupMenuBar property, which specifies the custom menu bar displayed by default when the application is loaded

    Allow Full Menus

    Sets the AllowFullMenus property, which allows or restricts the use of Access menus

    Allow Default Shortcut Menus

    Sets the AllowShortcutMenus property, which allows or restricts the use of standard Access shortcut menus (menus accessed with a right-click)

    Display Form/Page

    Sets the StartupForm property, which specifies the form displayed when the application is loaded

    Display Database Window

    Sets the StartupShowDBWindow property, which determines whether the Database window is visible when the application is opened

    Display Status Bar

    Sets the StartupShowStatusBar property, which determines whether the status bar is visible when the application is opened

    Shortcut Menu Bar

    Sets the StartupShortcutMenuBar property, which specifies that a menu bar be displayed by default as the shortcut (right-click) menu bar

    Allow Built-in Toolbars

    Sets the AllowBuiltInToolbars property, which indicates whether built-in toolbars are available to your users

    Allow Toolbar/Menu Changes

    Sets the AllowToolbarChanges property, which determines whether your users can customize toolbars in the application

    Use Access Special Keys

    Sets the AllowSpecialKeys property, which determines whether the user can use keys such as F11 to display the Database window, Ctrl+F11 to toggle between custom and built-in toolbars, and so on

    NOTE

    Notice the Use as Form and Report Icon property available when an Application icon is designated. When checked, the icon designated as the Application icon is used as the icon for forms and reports.

    As you might have guessed, many of these options apply only when you are running the application under the full version of Access (as opposed to the runtime version). You do not need to set the Display Database Window property, for example, if your application will be running only under the runtime version of Access. The Database window is never available under the runtime version of the product, so Access ignores this property when the user runs the application under the runtime version. Nevertheless, I like setting these properties to ensure that the application behaves as I want it to under

    both the retail and runtime versions of the product.

    You can set all the properties by using the Startup dialog box or by using code. If you use code, you must make sure that the property exists for the Database object before you set it. If the property does not exist, you must append the property to the Database object.

    Only users with Administer permission for the database can modify the Startup properties. If you want to ensure that certain users cannot modify the startup options of the database, you must make sure that they do not have Administer permissions.

    As part of setting startup options for your database, you should determine what code, if any, is run when the user loads the application. You can accomplish this in one of two ways. You can start the application with an AutoExec macro and then issue a RunCode action to execute a VBA procedure. The other option is to designate a Startup form for the application and then call a custom routine from the Open event of the Startup form. I

    always use the second option because it provides more control, and I can include error handling in the code module behind the startup form, whereas an AutoExec macro cannot contain error handling. The code shown in Listing 32.3 is called from the Open event of the Startup form for the time and billing application that was discussed earlier in the book. This code, and the rest of the code in this chapter, is located in the CHAP32.MDB database file on the sample code CD-ROM.

    Listing 32.3 Setting Options from a Startup Form Routine

    Private Sub Form_Open(Cancel as Integer)
    'Turn the hourglass on
    DoCmd.Hourglass True
    'Display the splash screen
    DoCmd.OpenForm "frmSplash"
    'Verify links and attempt to relink if necessary
    If LinkTables Then
    'If linking successful, load company info
    Call GetCompanyInfo
    Else
    'If linking unsuccessful, close the splash screen
    'and Quit
    DoCmd.Close acForm, "frmSplash"
    Cancel = True
    DoCmd.Quit
    End If
    'Turn hourglass off
    DoCmd.Hourglass False
    End Sub

    This routine, placed in the Open event of the startup form, first displays an hourglass. It uses the OpenForm method to open a form called frmSplash. The routine calls a user-defined function that ensures that the database tables are linked successfully. This LinkTables routine is covered in the "Automating the Process of Linking to Tables" section of this chapter. If the LinkTables function returns False, the code closes the frmSplash form and exits the application. As long as the tables' links have been established successfully, the routine proceeds to call a routine called GetCompanyInfo, where it loads frequently used information into a type structure. The hourglass mouse pointer is removed, and the splash screen is unloaded after it reaches a timer value.

    Securing the Application

    Don't fool yourself! Remember that the runtime version of Access in no way secures your application. It simply provides you with royalty-free distribution. You must perform all the same measures to secure your application under the runtime version of Access that you perform under the retail version of the product. The bottom line is that you must take measures to secure your application if you want it and its data to be secure. The basics of security are covered in Chapter 27, "Database Security Made Easy." The intricacies of security are covered in Chapter 28, "Advanced Security Techniques." Distributing your application as an MDE (compiled database) provides an additional level of security while improving performance and decreasing the size of the database file.

    Distributing Your Application as an MDE

    The process of creating an MDE file compiles all modules, removes all source code from your database, and compacts the destination database. All code will run, but the user will be unable to modify forms, reports, and modules. Besides protecting the objects in your database, this process reduces the size of the database and some of the overhead associated with it, thereby improving application performance. Creating and distributing an MDE file is not as simple as it might appear at first glance. Chapter 27 covers the process of creating an MDE file and the important issues that surround this file format.

    Adding Custom Help to the Application


    To add polish to your application and ensure that the help you provide to your users applies to what they are looking at in your application, you must provide a custom Help file. In essence, adding help to your application involves first creating Help files. You then must add help to the various objects in your application. There are many excellent tools available that can assist you in this.

    Testing and Debugging the Application


    Before you even bother trying to run your application under the runtime version, you should fully test and debug the application under the retail version of the product. When you are fairly confident that you have all the kinks worked out of the application, you are ready to test it in the runtime environment.

    Running and Testing the Application with the /Runtime Command-Line Switch


    If you have the Microsoft Visual Studio Tools for Office installed, Microsoft provides a very easy way to test an application and see how it will perform under the runtime version of Access without having to actually create distribution disks. You can do this by using the /Runtime command-line switch. The /Runtime switch forces Access to load in runtime mode. Here's how the command line reads:

    c:\program files\microsoft office\office\msaccess.exe c:\databases\chap32.mdb /runtime

    After you load the application with the /Runtime switch, you should once again test all aspects of the application. At times, you might want to test to see whether the application has been launched with the runtime or retail version of the product. You can accomplish this with the following code:

    If Not SysCmd(acSysCmdRuntime) _
    And CurrentUser <> "Admin" Then
    MsgBox "You aren't allowed here"
    End If

    The SysCmd function, when passed the constant acSysCmdRuntime, checks to see whether the application was launched using the runtime version of Access. In this case, if the program was run with the retail version of Access and CurrentUser is not Admin, a message is displayed, indicating that the user is not allowed. Of course, you could easily modify this routine to check for other users, and to quit the application if an unauthorized person attempts to launch the application without the runtime version of the product.

    NOTE

    The Microsoft Visual Studio Tools for Office and the Packaging Wizard were unavailable at the time of this writing. Therefore, some of this text might not apply to Access 2003. For an update of this section, please visit http://www.samspublishing.com and enter the ISBN for this book in the search box.

    Running the Packaging Wizard


    After you have fully tested and prepared your application for distribution, you are ready to run the Packaging Wizard. The Packaging Wizard walks you through all the steps required to build distribution disks that include all the components your application needs to run. You launch the Packaging Wizard from VBE, as follows:


  • Activate the VBE.

  • Select Packaging Wizard from the Add-ins menu. The Packaging Wizard starting dialog box appears.

  • The Packaging Wizard starting dialog box provides you with an introduction to the Packaging Wizard and what it does. Click Next to proceed to the next step.


  • Identifying Application and Package Information

    The first step of the wizard gives you the opportunity to

    • Designate the file you wish to package

    • Name the package that you are creating

    • Rename, delete, and duplicate packaging scripts


    Identify the file you want to package, and supply a package name. Then click Next.

    Supplying Application Information

    The second step of the wizard allows you to specify application information. You must supply

    • The application title

    • Your company name

    • Version information

    • The setup language


    Click Next when ready to continue.

    List of Files to Search for Dependency Information

    The third step of the wizard enables you to designate all files that you want to scan for dependency information. This information is used to ensure that all necessary files are included in the package. Click Add File to add any additional files that you wish to scan. Click Next when done.

    Inclusion of the Runtime

    The fourth step of the wizard enables you to determine whether the Access Runtime is included with the packaged application. If you opt to include the Access Runtime, you can designate whether you want to include system files and Internet Explorer 5.1. Finally, you can designate the language of the Access runtime that you wish to include. Click Next to continue.

    Modifying Installation Locations

    The fifth step of the Packaging Wizard allows you to designate where to install each file in the package. For each file, indicate where to place the file, and whether it is shared by other applications. Click Next when done.

    Inclusion of Database Components

    The sixth step of the wizard enables you to select the database components you want to include with your package. Click Next when done.

    Selecting Start Menu Items to be Created

    In the seventh step of the Packaging Wizard, you can designate Start menu groups and items that are created during the installation process. Click New Folder to create a new folder and New Shortcut to create a new shortcut. If you click a shortcut and click Properties, the Start Menu Item Properties dialog box appears. Designate the Name, Command Line, Start In path, Database information, and Profile information for the item. Click OK to return to the Start Menu Shortcuts step of the wizard. Click a shortcut and click Remove to remove a shortcut. Click Next when you're finished designating all options.

    Choosing a File to Run When the Installation Is Complete

    The eighth step of the Packaging Wizard allows you to specify a command to execute when the installation is complete. For example, you can designate that you want Access to open a ReadMe file when the installation of the application is complete. Click Next when done.

    The Final Step

    The final step of the Packaging Wizard prompts you either to build the setup program, or to save the package script without building it. Select the appropriate option and click Finish.

    Deploying the Application


    Before you can begin installing the application on workstations, you must deploy your project's packages to a distribution site. Once again, you accomplish this using the Packaging Wizard. Complete the following steps:


  • From the opening window of the Packaging Wizard, select Deploy.

  • In the first step of the wizard, you select the package to deploy. Click Next when ready.

  • The second step enables you to designate the type of deployment you want to perform. You can deploy to a folder, or via the Web. The steps that follow differ, depending on your selection. Click Next after you make your selection.

  • If you select Folder, the third step of the Packaging Wizard prompts you to designate where you want to deploy the package. You can deploy locally, or to a network. Make your selection and click Next.

  • In the final step, designate a name for the deployment script. This script is used for future deployments of the package. When ready, click Finish.

  • When the process is complete, a Deployment report appears. Click Save Report if you want to save the report. Click Close when done. You are returned to the opening screen of the Packaging Wizard.


  • Distributing the Application


    The most important thing you must do when packaging and distributing your application is test the application on a machine that has never had a copy of Access or any Access runtime application installed. This ensures that your application includes all required components. I like to keep a "virgin" machine available for testing my application setups. Here's what I do:


  • Use Symantec Ghost to create an image of the operating system drive on the test machine.

  • Install my application.

  • Test my application.

  • Restore from the Ghost image.


  • By following these steps, I ensure that I always have a "clean" machine on which to test my application. Obviously, it is imperative that you test

    all aspects of your application on the machine on which you performed the installation from your setup disks.

    TIP

    Several third-party software packages are available to help you to back up and restore your Windows installation easily. My favorite program is Ghost, available from Symantec.

    When you are ready to test the Setup process, follow these steps:


  • Select Run from the Windows Start menu.

  • In the Run dialog box, locate the Setup files that the Deploy portion of the Packaging Wizard created. Click OK.

  • After being notified of the setup's progress, the Application Setup dialog box appears.

  • Click OK to continue.

  • Select a location for the application installation.

  • Click the command button to install the application to the specified directory. The Choose Program Group dialog box appears. Select a program group and click Continue.


  • The installation process is completed. If you opted during the Packaging Wizard to create desktop shortcuts, they are created automatically when the Setup program is executed.


/ 544