• emailing from Access 97 (Access 97 Win 2k)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » emailing from Access 97 (Access 97 Win 2k)

    Author
    Topic
    #380825

    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

    Viewing 1 reply thread
    Author
    Replies
    • #639364

      It will send an email to each of the email addresses you have defined in the “to” field.
      Pat smile

    • #639380

      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.

      • #639460

        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

        • #639465

          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

    Viewing 1 reply thread
    Reply To: emailing from Access 97 (Access 97 Win 2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: