Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    emailing from Access 97 (Access 97 Win 2k)

    Hello again

    I'm trying to arrange for a database to email information to a clients, where we have their email address, a follow up contact once we've quoted them for product.

    Looking at the help, I can use 'docmd.sendobject' in VBA, my question is this, if I set the string expression for the 'to' argument will this send an email to each address, or just one email to the first address it finds

    My apologies for asking this, before I try it out but I'm waiting for my PC to be sorted out with either a MAPI compliant email client or the relevant parts of VIM, to allow me to try my theory.

    Thanks

    Ian

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: emailing from Access 97 (Access 97 Win 2k)

    It will send an email to each of the email addresses you have defined in the "to" field.
    Pat <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: emailing from Access 97 (Access 97 Win 2k)

    The effect of putting multiple addresses in the "to" field is the same as putting multiple addresses in the To line of you email program. Everyone gets the message, and everyone sees who else got it.

    Generally you don't want this, so instead a code loop is written that works through a recordset , setting the "to" field, sending the message, then moving on the the next record.
    Regards
    John



  4. #4
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: emailing from Access 97 (Access 97 Win 2k)

    OK, I didn't explain what I was talking (typing :-) ) about very well. What I want to do is set the string expression for the 'to' argument to a field in a query (more likely to use the 'bcc' argument though, to avoid every one knowing who else got the email). So, will it use every email address in the query field, or do I need to write some code to make Access step through all the records in the query?

    Sorry about the poor original question.

    Ian

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: emailing from Access 97 (Access 97 Win 2k)

    You will need to loop through the records of the query.

    Here is code that sends one e-mail to all e-mail addresses from a field named E_Mail in a query named qryAddresses. The addresses are put into the BCC field.

    Sub SendMailToAll()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strAddressees As String

    On Error GoTo Err_Handler

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("qryAddresses")

    ' Concatenate addressees separated by semicolons
    Do While Not rst.EOF
    If Not IsNull(rst!E_mail) Then
    strAddressees = strAddressees & rst!E_mail & ";"
    End If
    rst.MoveNext
    Loop

    ' Send one e-mail with addressees in Bcc field
    If strAddressees <> "" Then
    DoCmd.SendObject BCC:=strAddressees, _
    Subject:="Test", _
    MessageText:="Hello World"
    End If

    Exit_Handler:
    On Error Resume Next
    rst.Close
    Set rst = Nothing
    Set dbs = Nothing
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, vbExclamation
    Resume Exit_Handler
    End Sub

    and here is code that sends an individual e-mail to each e-mail address:

    Sub SendMailToEach()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset

    On Error GoTo Err_Handler

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("qryAddresses")

    Do While Not rst.EOF
    If Not IsNull(rst!E_mail) Then
    ' Send e-mail to each addressee
    DoCmd.SendObject To:=rst!E_mail, _
    Subject:="Test", _
    MessageText:="Hello World"
    End If
    rst.MoveNext
    Loop

    Exit_Handler:
    On Error Resume Next
    rst.Close
    Set rst = Nothing
    Set dbs = Nothing
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, vbExclamation
    Resume Exit_Handler
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •