Results 1 to 6 of 6
  1. #1
    JJCHCK is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    30

    email with outlook.application

    hi everybody
    i have a button to send email to different peoples with their own information


    the button is "libreria outlook"

    sorry for my english

    i attach my mdb

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi,

    ad what is your question?

    gr
    NG

  3. #3
    JJCHCK is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    30
    if you click "libreria outlook" the mail stop at the first record (daveweckel)
    so the loop stops
    What wrong on my code?

  4. #4
    JJCHCK is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    30
    eureka
    the code " Set outMsg = outApp.CreateItem(olMailItem)"
    must be set after "Do until rs.eof

  5. #5
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi,

    indeed your code needed a bit shuffling around. I also added some code to check if the recordset isn't empty and an exit point so you don't get into the error code even with no error:

    Code:
     Private Sub Comando32_Click()
         On Error GoTo err:
     
     Dim rs As DAO.Recordset
     Dim VDb As DAO.Database
     Dim VEmail, VAgente As Variant
      
     Set VDb = CurrentDb
     Set rs = VDb.OpenRecordset("SELECT * FROM ResiEmail")
    
     DoCmd.OutputTo acReport, "ResiEmail", acFormatPDF, "C:\Documents and Settings\junior\Desktop\Rpt_Resi\ResiEmail.pdf"
    ' DoEvents
     
     Dim outApp As OUTLOOK.Application, outMsg As MailItem
     
     Set outApp = CreateObject("Outlook.Application")
     Set outMsg = outApp.CreateItem(olMailItem)
    
     'VAgente = rs.Fields("agente")
        'VPAgente = VAgente
     If Not (rs.BOF And rs.EOF) Then 'take care of the possibility that the recordset is empty
         rs.MoveFirst
         Do While Not rs.EOF
            If VAgente = rs.Fields("agente") Then
                'rs.MoveNext
            Else
                VAgente = rs.Fields("agente")
                VPAgente = VAgente
                VEmail = rs.Fields("email")
                With outMsg
                   .Importance = olImportanceHigh
                   '.SendUsingAccount = outApp.Session.Accounts.Item(2)
                   .ReadReceiptRequested = True ' conferma lettura
                   .OriginatorDeliveryReportRequested = True ' conferma recapito
                   .To = VEmail
                   .CC = "jjjjjjj@tiscali.it"
                   .BCC = "jjjjjjj@tiscali.it"
                   .Subject = "oggetto"
                   .Body = "messaggio"
                   .Attachments.Add ("C:\Documents and Settings\junior\Desktop\Rpt_Resi\ResiEmail.pdf")
                   .Display
                   '.Send
                End With
        
                Debug.Print (VEmail)
           End If
                 
            rs.MoveNext
        Loop
    End If
    
       
       Set outApp = Nothing
       Set outMsg = Nothing
    exit_Commando:
        Exit Sub
        
    err:
        MsgBox (err.Description & err.Number)
        err.Clear
    End Sub
    gr
    NG

  6. #6
    JJCHCK is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    30
    thanks a lot
    you have reply so quickly


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-29-2011, 12:33 PM
  2. Send email from Access thru Outlook
    By ZMAN in forum Forms
    Replies: 2
    Last Post: 11-27-2010, 06:10 PM
  3. Passing Email Address Into Outlook
    By cg1465 in forum Access
    Replies: 1
    Last Post: 10-01-2010, 07:59 AM
  4. Exporting Outlook email addresses
    By noidea in forum Import/Export Data
    Replies: 0
    Last Post: 08-01-2009, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums