Ado

The ActiveX Data Objects (ADO) model isn't the best method for working with Access data, but it does offer some extra features that are very handy for working with text files, in particular the Stream object. The ADO case in the cmdCreateEMails_Click event procedure starts by setting a variable to a Stream object in the ADO object model (note that the object model prefix is ADODB), using the New keyword. The next line opens the new Stream object (you can't write to it unless it is open). 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 stream using the WriteText method. To create two blank lines in the text file, WriteText is then used with two vbCrLf constants (representing a CR + LF, meaning carriage return plus linefeed — antique terminology dating back to the days of manual typewriters).

j J J"^/ ji You need a reference to the ActiveX Data Objects 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. At the end of the Case, a final line is written, and the stream is saved to a text file using the SaveToFile method with the adSaveCreateNotExist option, which creates the file if it does not exist.

0 0

Post a comment