Access.2007.VBA.Bibl..

(John Hannent) #1

I


n 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 docu-
ments, 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 CommonDialogcontrol 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
CommonDialogcontrol.

See Chapter 8 for information on working with Outlook
folders.

Another advance came with the Scripting Runtime library, which provided a
FileSystemObjectobject (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 FileDialogobject (part of the Office

CROSS-REFCROSS-REF


IN THIS CHAPTER


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

Working with Files


and Folders

Free download pdf