Results 1 to 4 of 4
  1. #1
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72

    How to run outlook sub through access

    Hi all,



    I have an outlook sub written using outlook vba. How can i call the sub in outlook through access vba?

    Thanks,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Normally you dont need the outlook vba, just SENDOBJECT (it sends via outllook)
    DoCmd.SendObject acSendReport, vRpt, acFormatPDF, vTo, , , vSubj, vBody

    but if you need outlook then, you MUST
    ADD THE OUTLOOK APP IN REFERENCEs, checkmark OUTLOOK OBJECT LIBRARY in the vbE menu, Tools, References

    Code:
    '------------
    Public Sub ScanAndEmail()
    '------------
    Dim vTo, vSubj, vBody, vRpt
    Dim vFilePath
    dim i as integer
    For i = 0 To lstEAddrs.ListCount - 1
       vRpt = lstEAddrs.ItemData(i)
       lstEAddrs = vRpt
       vTo = lstEAddrs.Column(2)
       
       vBody = "body of email"
       vSubj = vRpt
       vFilePath = ""  'path of the snapshot or XL or PdF
       
       Call Email1(vTo, vSubj, vBody, vFilePath)
    Next
    End Sub
    
    '-------
    'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!!   checkmark OUTLOOK OBJECT LIBRARY in the vbE menu, Tools, References
    '-------
    Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody,optional ByVal pvFile) As Boolean
    Dim oApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    On Error GoTo ErrMail
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(olMailItem)
    With oMail
        .To = pvTo
        .Subject = pvSubj
        .Body = pvBody
        If Not Ismissing(pvFile) Then  .Attachments.Add pvFile, olByValue, 1
        
    .Send
    End With
    EmailO = True
    Set oMail = Nothing
    Set oApp = Nothing
    Exit Function
    ErrMail:
    MsgBox Err.Description, vbCritical, Err
    Resume Next
    End Function

  3. #3
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72
    Thanks for the Reply,

    Im not trying to send an email, I already written the outlook macro which does various things including looping through emails in certain outlook folders. All i need to do is essentially call and outlook macro. Is that possible?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Thats the code i sent. If you want to call your code, just make it a FUNCTION, then in a macro use:
    RUNCODE myFcnt()

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

Similar Threads

  1. access to outlook
    By DiGamer in forum Access
    Replies: 1
    Last Post: 10-04-2014, 10:26 AM
  2. Replies: 11
    Last Post: 05-20-2014, 11:32 AM
  3. Access and Outlook
    By sdc1234 in forum Access
    Replies: 4
    Last Post: 07-01-2013, 08:19 AM
  4. Assigning Outlook task from shared Outlook mailbox
    By Remster in forum Programming
    Replies: 2
    Last Post: 11-16-2011, 04:38 AM
  5. MS-Access into Outlook - possible?
    By techexpressinc in forum Access
    Replies: 0
    Last Post: 01-09-2009, 01:44 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