gather e-mail addresses...

doran_doran

Registered User.
Local time
Today, 11:18
Joined
Aug 15, 2002
Messages
349
Ok, I can gather all the e-mail addresses in my temporary table. Showing in the subform on a main form and they are not tie (form and subform).

How can I get all the e-mail addresses together seperated by comma before hitting "Send Mail" button.

Thanks


My Lotus Note Send e-Mail Code which works fine for one e-mail address:
=====================
Public Sub SendNotesMail()

Dim Subject As String, Recipient As String, BodyText As String, SaveIt As Boolean

'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
'The next line if for attachment
'Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)

'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")

'Define recipient, body test, subject
Recipient = Me.StrRecipient ' strRecipient is a text box on my main form
BodyText = Me.strOriginalPassword
Subject = "Your Password"


'Next line only works with 5.x and above. Replace password with your password
'Session.Initialize

'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string or using above password you can use other mailboxes.

If Not fOSUserName = Me.txtUser Then
MsgBox "You can only request password when you logged onto Windows NT with you AIG Valic ID"
Exit Sub
Else

UserName = Session.UserName
MailDbName = left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"

'Open the mail database in notes
Set Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If

'Set up the new mail document
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SaveMessageOnSend = SaveIt

'Set up the embedded object and attachment and attach it
'If Attachment <> "" Then
' Set AttachME = MailDoc.CreateRichTextItem("Attachment")
' Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment, "Attachment")
' MailDoc.CreateRichTextItem ("Attachment")
'End If

'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient

MsgBox "Your password has been sent. However, You may have to grant Plan Manager when prompted by Lotus Notes."

'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
'Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing

End If

End Sub
 
Do you just need to get all the addresses concatenated into a comma-delimited string? & is the string concatenation operator in VBA.

Your addresses are in a table... so I assume you're opening a recordset. So you'd need to loop through the recordset and concatenate the string together. Something like this:

Code:
rst.MoveFirst
recipients = rst.Fields("Address")
rst.MoveNext
Do While Not rst.EOF
    recipients = recipients & ", " & rst.Fields("Address")
    rst.MoveNext
Loop
 
Almost Working...

Hi Scottn,

We are almost done. Only last record is being pulled.

Me.txtTotalRecipients is a text box on my form to save this.

Code
=============================================
Private Sub cmdSaveMail_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = currentdb()
Set rst = db.OpenRecordset("tbltmpRecipients", dbOpenDynaset)

rst.MoveFirst
Recipients = rst.Fields("TotalRecipients")
rst.MoveNext

Do While Not rst.EOF
Recipients = totalrecipients & ", " & rst.Fields("totalrecipients")
rst.MoveNext
Loop

Me.txtTotalRecipients = Recipients

End Sub
 
try these corrections:

Code:
Private Sub cmdSaveMail_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
[B]Dim Recipients as String[/B]

Set db = currentdb()
Set rst = db.OpenRecordset("tbltmpRecipients", dbOpenDynaset)

rst.MoveFirst
Recipients = rst.Fields("TotalRecipients")
rst.MoveNext

Do While Not rst.EOF
Recipients = [B]Recipients[/B] & ", " & rst.Fields("totalrecipients")
rst.MoveNext
Loop

Me.txtTotalRecipients = Recipients

End Sub
 
Genius WORK

Hello Scottn,

YOU ARE GENIUS. IT WORKS LIKE A CHARM.

THANKS A BILLION FOR BEING SOOOO PROMPT AND HELPING ME.
 

Users who are viewing this thread

Back
Top Bottom