Programmability Enhancements

graphics/new.gif

Every Access upgrade has added new events, properties, and methods, but Access 2003 is an exception. The only programmability enhancements in the Access 2003 upgrade are changes to the ExportXML and ImportXML methods, and programmatic access to properties associated with smart tags. These topics are beyond the scope of this book. Thus, the following sections, which describe new events, properties, and methods introduced by Access 2002, are intended for Access 97 and 2000 users who upgrade to Access 2003.

graphics/2002_icon.gif

The number of new programming elements added by Access 2002 was much fewer than most previous upgrades. For example, the upgrade from Access 97 to 2000 replaced VBA 5.0 with 6.0, and introduced the Office VBA Editor. The VBA 6.0 upgrade added hundreds of new programming elements.

Access 2002 Events for Forms, Controls, and Batch Updates

Most Access upgrades add new events for forms and controls, which results in Access having unrivaled data-related event granularity. Table 1.2 lists the three events for forms and controls added by Access 2002. Each of these events has its VBA event counterpart, which is shown in parentheses.

Table 1.2. Events for Forms and Controls Added by Access 2002

Event

When the Event Fires

On Undo (Undo)

After the user has applied the Undo command to return a control or form to its original (clean) state (the opposite of the On Dirty event)

On Mouse Wheel (MouseWheel)

Movement of the mouse wheel (forms only)

Access 2002 Properties and the Printers Collection

One of the most important Access 2002 programming features is the addition of the Printers collection, which lets you assign a particular Printer object from the collection to print a form or report. Addition of the Printers collection and Printer object eliminates the cumbersome PrtDevMode and PrtDevNames programming required by earlier Access versions. Table 1.3 lists the properties added by Access 2002 that apply to forms, reports, and controls. Table 1.4 lists only higher-level Access properties.

Table 1.3. Properties of Forms, Reports, and Controls Added by Access 2002

Collection or Property

Purpose

Application.Printers

Collection of local and network Printer objects accessible to the application

Form.Printer

Assigns a member of the Printers collection to print a form

Report.Printer

Assigns a member of the Printers collection to print a report

Control.Recordset

Binds a DAO.Recordset or ADODB.Recordset object to a list box or combo box control

Report.Recordset

Binds a DAO.Recordset or ADODB.Recordset object to a report

Report.Shape

Returns the text of the Shape command used to create a grouped report

Table 1.4. Application, Project, and Access Object Properties Added by Access 2002

Property

Purpose

Application.Build

Returns the Access build number

Application.BrokenReference

Returns True if the VBA project contains broken references

CurrentProject.FileFormat

Returns the version of the Access project

AccessObject.DateCreated

Returns the date and time when an Access object (form, report, macro, or module) was created

AccessObject.DateModified

Returns the date and time of the last design change to an Access object

Methods Added by Access 2002

Table 1.5 lists control and form methods added by Access 2002. The AddItem and RemoveItem methods for Access combo- and list boxes are similar to Visual Basic's methods for these two control types. The two Move methods simplify changing the position or altering the size of a control or form.

Table 1.5. Control and Form Methods Added by Access 2002

Object.Method

Purpose

Control.AddItem

Adds an item specified by a string Item value and optional Index argument to a combo box or list box. The RowSourceType property of the control must be set to Value List.

Control.RemoveItem

Removes the item specified by the value of the Index argument.

Control.Move

Sets the Left, Top, Width, and Height properties of a control.

Form.Move

Sets the Left, Top, Width, and Height properties of a form, overriding the Moveable property value.

The eight added methods of the Access Application object, listed in Table 1.7, let you duplicate with VBA code actions that ordinarily take place in the UI. For example, the ExportXLM and ImportXML methods correspond to the File, Export and File, Get External Data, Import commands with XML Documents (*.xml) specified in the Export or Import dialog.

Table 1.7. Updated Application Methods Added by Access 2002

Method

Purpose

Application.CompactRepair

Compacts and attempts to repair a specified Jet .mdb file

Application.ConvertAccessProject

Convert an .mdb or .adp file to the specified Access version

Application.CreateNewWorkgroupFile

Generates a new workgroup (.mdw) file for shared Access applications

graphics/new.gif

Application.ExportXML

Exports an Access object to an XML file

graphics/new.gif

Application.ImportXML

Imports an XML file into an Access object

Application.FileDialog

Opens the File Open or File Save As dialog, eliminating the need to use the Common Dialog ActiveX control

Application.OpenCurrentDatabase

Adds the capability to specify a database password

Application.SetDefaultWorkgroupFile

Changes the current Access workgroup file to an .mdw file you specify

Visual Basic Functions

Access 2003 queries against Jet databases and VBA code support the nine VBA 6.0 functions added by Office XP listed in Table 1.9. The added Format... functions eliminate the need to specify format strings when you use the general-purpose Format function in a Jet query or code.

Table 1.9. VBA 6.0 Functions Added by Office XP

Function

Description

FormatCurrency

Formats a numeric value with a currency symbol, a specified number of digits after the decimal point, leading digit, negative numbers in parentheses, and digits grouped with a delimiter. By default, the function uses the computer's Regional Settings values for currency.

FormatDateTime

Formats a Date value in one of four standard date and time representations.

FormatNumber

Same as FormatCurrency but doesn't display the currency symbol.

FormatPercent

Same as FormatCurrency but multiplies the value by 100 and adds a trailing % symbol.

InstrRev

Searches for the occurrence of a substring within a string value beginning at the end of the string.

MonthName

Returns the full or abbreviated name of the month from numeric values 1 through 12.

Replace

Returns a string in which a specified substring replaces one or more occurrences of the value's substring.

StrReverse

Returns a string with the characters in reverse order.

WeekdayName

Returns the full or abbreviated name of the day of the week from numeric values 1 through 7 with the capability to specify the first day of the week.

Caution

If you use any of these new functions in Jet queries or VBA code, your Access 2003 application saved in Access 2000 format won't run under Access 2000.




Special Edition Using Microsoft Office Access 2003
Special Edition Using Microsoft Office Access 2003
ISBN: 0789729520
EAN: 2147483647
Year: 2005
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net