My OS is windows 7. The code I have here was developed by the Gurus here on this Forum. This is a small database. And it extracts the database,concaternates into a string, so that I could copy and paste it into an email client.
However the database also contains the names of spouses who use the husband's or wive's email address, thus there will be duplicates in the present code.
For ease of reference, I think it is should be implemented from the Else line.
I would like the code, when it first reiterates for the first record, to add the name to the list, but after that from the 2nd record to the end of the file, to first check if this email is already in the List, if Yes, do not add it, if No, then add.
Those are my novice thoughts of how the program should run, but I am sure the Experts would be able to suggest a better version of it. Thank you.
Private Sub mailemailreport_Click()
Dim rst As DAO.Recordset
Dim strDistList As String
Set rst = CurrentDb.OpenRecordset("Seniors Club")
Do While Not rst.EOF
strDistList = strDistList & rst!Email & ";"
If MsgBox("Print Email distribution list to file?", vbYesNo, "Print?") = vbYes Then
Dim lFile As Long
'/get the next available File handle
lFile = FreeFileHandle
'/delete the file if it exists
If Dir(CurrentProject.Path & "\EmailList.txt") <> "" Then Kill CurrentProject.Path & "\EmailList.txt"
'/Now open the file
Open CurrentProject.Path & "\EmailList.txt" For Output As #lFile
'/write to that file
Print #lFile, strDistList
'/now close the file
strDistList = Left(strDistList, Len(strDistList) - 1)
Me.Text46 = strDistList
Set rst = Nothing