File SystemObject

The FileSystemObject object library provides an alternate approach to working with text files, using the TextStream object. The FSO case in the cmdCreateEMails_Click event procedure starts by creating a FileSystemObject variable and then creating a TextStream variable using the CreateTextFile method. A string of introductory text to be written to the file is saved to the strText variable and then written to a line in the text file using the WriteLine method. To create two blank lines in the text file, the WriteBlankLines method is then used with the Lines argument set to 2.

• r r^'-'-.'fV You need a reference to the Microsoft Scripting Runtime object library to support ■ ■■ this code.

The code iterates through the ItemsSelected collection of the lstSelectContacts listbox, checking each record for required fields (Email and CompanyName). For each record that lacks data in one or both of the required fields (and thus won't get an email message), an If . . . Then statement writes a line containing information on which record has been skipped, and why, plus another blank line. When all the items have been processed, a final line is written to the text file.

0 0

Post a comment