This chapter has described the components of the Outlook object model you need to understand in order to work with Outlook objects and has given you examples of exporting Access data to Outlook and importing Outlook data into Access (or linking to it), as well as creating new Outlook items based on data changes in Access tables. While there are both advantages and disadvantages to storing contacts in Access and Outlook, I recommend exporting tasks and appointments from Access tables to Outlook, so they can be managed in its superior interface. For contacts, the decision depends on which is more important to you: the convenience and attractive interface of Outlook contacts, or the more sophisticated Access relational database interface, allowing you to set up one-to-many links between companies and contacts, or contacts and phones or IDs.

In the previous chapters I discussed creating Word documents, Excel worksheets, and various types of Outlook items using VBA Automation code. But these aren't the only types of documents you need to work with — sometimes you need to create a plain text document, or import data from one into an Access table. But, before you can work with these documents, you need to work with folders. This chapter covers writing code that works with Windows Explorer folders and text files, using several different methods.

As Access versions have progressed, the available tools for working with files or folders have advanced. In Access 1.0, the notoriously cryptic callback function was the only way to get a list of files to display in a combo box or listbox. By Windows 95, the CommonDialog control was a possibility, at least if you had the Developer edition of Office. But the CommonDialog control was plagued with version problems — if you put one version of it on a form, and sent the database to another person who had a different version of the control, the other person would just get the mysterious message "There is no object in this control" on opening the form with the CommonDialog control.

j f~, rj f- -Vi-Vt 'rj, See Chapter 8 for information on working with Outlook j '^.J^-.rr folders.

Another advance came with the Scripting Runtime library, which provided a FileSystemObject object (yes, that's two objects!) that is very useful for finding, working with, or creating files and folders in code. However, it doesn't offer a dialog-type interface for selecting files or folders.

The next advance came with Office XP, which introduced a new tool for working with files and folders. The FileDialog object (part of the Office


Creating Windows folders

Creating FolderPicker and FilePicker dialogs using the Office FileDialog object

Writing data to text files using the FileSystemObject, legacy VB statements, and ADO

Reading data from text files using the FileSystemObject, legacy VB statements, and ADO

Loading files into Attachment fields and saving attachments to files object model) lets you pop up a dialog for selecting a file or a folder, with several dialog type options. This dialog lets users easily select a file or folder, whose name can then be used in code for further operations.

There is no longer any reason to use a Callback function or the CommonDialog control for working with files and folders, so this chapter covers using the FileSystemObject and the FileDialog object for working with files and folders, and components of the ADO object model and legacy VB statements for working with text files.

0 0

Post a comment