title: Button for sending email with vba code
body: <p>I have created a button on my Access 2010 form. I want to send an email to all my customers in my Table and add a report to email. Also my report is customer based therefore i had to create report by using form. I couldnt manage to get a customer based report without form.</p>
  
  <p>I managed to most of the project. However, when i say go to next record on form and change the information my code doesnot work. acNext is not doing its job. Is there a way to make it work?</p>
  
  <p>Comments and variables are on my main language if you dont mind. </p>
  
  <p>Thanks</p>
  
  <pre><code>Public Sub Komut15_Click()
  
  
      Dim oApp As New Outlook.Application
      Dim oemail As Outlook.MailItem
      Dim fileName As String, todaydate As String
  
  
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
  
      Set db = CurrentDb
      Set rs = db.Openrecordset("SELECT Ad, Soyad, Email, Limit, Adres FROM Musteriler Sorgu")
  
      Do Until rs.EOF
  
      On Error Resume Next
      DoCmd.GoToRecord , , acNext
  
  
  
          'Raporu müşteri bazında olması için düzenliyoruz
  
           DoCmd.OpenReport "MusteriRaporu", acViewReport, "", "[Forms]![MusteriFormu]![Ad]=[Musteriler]![Ad]", acNormal
  
  
          'Raporu pdf file olarak dışa aktarıyoruz
          todaydate = Format(Date, "DDMMYYYY")
          fileName = Application.CurrentProject.Path &amp; "\MusteriRaporu_" &amp; todaydate &amp; ".pdf"
          DoCmd.OutputTo acReport, "MusteriRaporu", acFormatPDF, fileName, False
  
  
  
          Set oemail = oApp.CreateItem(olMailItem)
          oemail.To = rs.Fields("Email")
          oemail.Subject = Me.Firma_Adı &amp; " Bakiye Raporu"
          oemail.Body = "Bakiye raporunuz ektedir."
          oemail.Attachments.Add fileName
  
  
          With oemail
              If Not oemail.To &lt;&gt; Me.Email Then
                  .Send
                  MsgBox "Email Gonderildi"
  
              Else
                  MsgBox "Mail adresi hatalı!"
  
              End If
  
          End With
       rs.MoveNext
  
      On Error Resume Next
      DoCmd.GoToRecord , , acNext
  
      Loop
  
  
      rs.Close
  
      Set rs = Nothing
      Set db = Nothing
  
  
  
  End Sub
  </code></pre>