visual basic for application - microsoft access 2003 finishing the application

10
Visual Basic for Application - Microsoft Access 2003 Finishing the application

Upload: henry-gibbs

Post on 21-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Visual Basic for Application - Microsoft Access 2003

Finishing the application

Page 2: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST2

Introduction

• After working so hard to develop an advanced Access application using VBA, it is important to make sure that the application is capable of performing well and handling the number of users you expect.

• You also want to make sure that the end users are not able to modify the database source code and design without the proper permission.

• After you have fine-tuned, secured, and tested the application, you are ready to implement the application by distributing it to end users. However, after you distribute the application to end users, your job is still not finished.

• Access applications need to be backed up and compacted periodically to ensure that they remain in good working order and that they can be recovered from a backup if corruption or deletion occurs.

Page 3: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST3

Optimizing Your Applications

• General Design Guidelines to help improve the actual performance of your applications:– Minimize the code and objects in a form. Move the code to a standard

module. The more complicated a form is, the longer it takes to load.– Minimize the use of subforms because two forms are in memory.– Write reusable modules that so you are not rewriting the same code in

slightly different ways multiple times. This reduces the amount of code in your application and helps improve speed. For example, instead of having one procedure that enables all controls in one form, another that disables all controls in another form, and two others that disable controls in each of those same forms, write a generic module that enables or disables all controls on the specified form based on whether the enable or disable flag is passed as a variable.

– Eliminate code that is not used.– Make sure that your application is compiled. Also, consider compiling

your application into an ACCDE file as described later in this chapter.– If you have all the user-interface objects in one database and the data

tables in another (Access or other) database, open the database with the user interface exclusively for faster performance

Page 4: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST4

Optimizing Your Applications

• Improving Data Access:– Minimize the number of database connections open. For example, if

you use a bound form, it maintains a constant connection to the database. Consider switching to an unbound form that connects to the database to retrieve the data, disconnects, and reconnects when it needs to update the data.

– Use a query as the source of a form, control, or ADO recordset that returns only the rows you need to work with instead of opening an entire table.

– Make sure that your query is written correctly. For example, make sure to retrieve only the columns that are being used. Also make sure that you are using the correct type of join.

– Make sure the type of cursor being used is not more than you really need. For example, if you are not modifying the data, use a read-only cursor.

– Use proper indexes on the tables to reduce the number of table scans. Add indexes to the fields that are used to join tables together and are frequently used to retrieve data. This will save Access from having to perform a scan of the entire database to find the desired record. However, do not add indexes on every field in the database. This will actually degrade performance more than having no indexes at all.

Page 5: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST5

Optimizing Your Applications

• Running the Performance Analyzer:– Access comes with a Performance Analyzer utility that will

analyze the selected objects and make suggestions to help improve the speed. You must have the database you wish to analyze open in order to run the analyzer.

– Select Database Tools and then click on Analyze Performance in the Analyze ribbon.

– Select the All Object Types tab. Click the Select All button and then select OK. This selects all the objects in the database to analyze. The analyzer runs, and a screen is displayed, which makes various suggestions on ways to improve the performance of the application.

Page 6: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST6

Securing Your Application

• You have various ways to add security to your application. You can implement one or more of these techniques, depending on the type of security that is required for your application.

• Adding a Database Password:– One way to add security to your database is to require a user to input a

password before the database can be opened. This is called file-level security. After the database file has been opened by specifying the correct password, the user can do anything to the database unless the other security features are implemented.

– To do it, select the Database Tools ribbon Encrypt with Password option. You will be prompted to enter a password for the database.

• Adding a Password for VBA Code:– Adding a password to the database as described in the prior section does not

keep the user from seeing your source code.– To add a password for the VBA code, open the Visual Basic Editor. Then,

select Tools ProjectName Properties. Select the Protection tab and Specify the Lock Project For Viewing option, and fill in a password that must be specified in order to view the source code.

Page 7: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST7

Securing Your Application

– After you click OK, the specified password will be required in the future before

the source code can be viewed or modified. • Encrypting a Database:

– Even after you add to your application the security features discussed so far, your application is still not totally secure. Someone could still view the contents of the database with a tool that can view partitions on disk and decipher data.

– To do so, select the Database Tools ribbon and then Encode Database in the Database Tools group. Access then prompts you to specify a password. After you click OK, the entire database will be encrypted. In order for you to use the application after it has been encrypted, Access will have to decrypt the information. This means that encrypting the database will slow down performance as much as 20%. If this performance degradation is a problem for your application, decryption is not a good option.

Page 8: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST8

Maintaining the Application

• Just because you have deployed your application to end users does not mean that your job is finished. It is important that you periodically compact the database to keep it in good working order and that you make periodic backup copies.

• Compacting and Repairing the Database:– You can compact and repair Access databases to reduce the amount

of space they take up and to repair problems if Access discovers any.– To compact and repair an Access database, select the Office Button

Manage Compact and Repair Database.• Making Backup Copies of the Database:

– It is very frustrating to lose the data and have to recreate it again. The same concept holds true for your Access applications. Access databases are file-based, which means that a lot of the information is contained in the single ACCDB file. Because so much is contained in a single file, and because it would be easy for a user to delete the database file from the network, it is extremely important that you make periodic backups of both the database tables and the user interface.

– To back up an Access database, select the Office Button Manage Backup Database. You will be prompted to specify a file name and path where you want the backup saved. Click OK, and the backup copy will be created.

Page 9: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST9

Any Question?

Page 10: Visual Basic for Application - Microsoft Access 2003 Finishing the application

Copyright © 2007 - CIST10

The End