Outlook To: field populates based on a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slenish
    Contributor
    • Feb 2010
    • 283

    #1

    Outlook To: field populates based on a table

    Hello,

    I am using Access to Generate an Outlook Email based on a button click. Currently I have this working with no problem but I want to populate the To: field of the email based on email addresses that are listed in a table instead of hard coding them in. I currently have the below code working but it will only pull in the last email in the table. I was wondering if anyone could help me adjust it so it will loop through the table pulling in all of the addresses?

    Apprecaite the help!

    Code:
    Private Function ToNam() As String
    
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("EmailList")
    
    With rst
        .MoveFirst
         Do Until rst.EOF
            If IsNull(.Fields(0)) = False Then
            ToNam = .Fields(0)
            End If
        .MoveNext
       Loop
    End With
    
    Set rst = Nothing
    Set db = Nothing
    End Function
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You need to append to the variable with each iteration. Right now you're just replacing the value.

    Comment

    • slenish
      Contributor
      • Feb 2010
      • 283

      #3
      What do you mean by Append? Like an Append Query?

      Comment

      • dsatino
        Contributor
        • May 2010
        • 393

        #4
        What rabbit said...
        ToNam= ToNam & ";" & .fields(0)

        that will give you a leading ";" which I don't think bothers Outlook. If it does than you just need to add an IF statement in there.

        Comment

        • slenish
          Contributor
          • Feb 2010
          • 283

          #5
          Hi dsatino,

          very nice my friend that worked perfectly.

          Originally I was trying that at then end of the statement

          ToNam = .fields(0) & ";"

          but was getting no where.

          Appreciate the help!!
          Slen

          Comment

          Working...