The third case uses legacy VB statements from the earliest days of Access; no object model reference is needed. The Open strFile For Output As #1 statement creates and opens the text file for output. 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 rather unintuitive Print #1 method. To create two blank lines in the text file, two Print #1 lines with no argument are used.

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 another blank line and a line containing information on which record has been skipped.

At the end of the case, a final line is written, and the file is closed using the Close #1 statement. This does not delete the text file, just closes it.

0 0

Post a comment