Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Eug7 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2023
    Posts
    13

    How to handle users with various office libraries/Outlook OLE

    this is my code used to email out of access 2016. My reference library selected is: Microsoft Office 16.0 Access database engine object, Microsoft Outlook 16.0 Object Library. My DB errors with user machines with different office versions, anywhere from 14 to 19 to 21. Is it possible on DB open to have access select the Office version library reference dynamically on the users machine? Is this a complicated thing to implement?




    Option Compare Database
    Public WithEvents app As Outlook.Application
    Public WithEvents msg As Outlook.MailItem


    Private Sub Class_Initialize()


    Set app = CreateObject("Outlook.Application")
    Set msg = app.CreateItem(olMailItem)


    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Look into "late binding".
    One example
    https://stackoverflow.com/questions/...ok-from-access
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Eug7 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2023
    Posts
    13
    Quote Originally Posted by Micron View Post
    Look into "late binding".
    One example
    https://stackoverflow.com/questions/...ok-from-access

    Not sure I know how to implement. I get an error at .Subject = gOutlookSubject

    Dim olApp As Object
    Dim objNS As Object
    Dim olFolder As Object

    Set olApp = CreateObject("Outlook.Application")
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolder = objNS.GetDefaultFolder(olFolderInbox)

    With olFolder
    '/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
    .Subject = gOutlookSubject
    .HTMLBody = strFormat & gOutlookBody & "<br>" & "<br>" & strCompany
    .To = gOutlookEmail
    .CC = gOutlookEmailCC

    If intInclude = 1 Then
    If Not Dir(gPath & gOutlookAttachment & ".xlsx") = "" Then
    .Attachments.Add (gPath & gOutlookAttachment & ".xlsx")
    End If
    ElseIf intInclude = 2 Then
    If Not Dir(gOutlookAttachment) = "" Then
    .Attachments.Add (gOutlookAttachment)
    Kill gOutlookAttachment
    End If
    End If

    .Display

    End With

  4. #4
    Eug7 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2023
    Posts
    13
    Not sure I know how to implement. I created the below as a function and get an error at .Subject =



    Dim olApp As Object
    Dim objNS As Object
    Dim olFolder As Object

    Set olApp = CreateObject("Outlook.Application")
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolder = objNS.GetDefaultFolder(olFolderInbox)

    With olFolder
    '/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
    .Subject = gOutlookSubject
    .HTMLBody = strFormat & gOutlookBody & "<br>" & "<br>" & strCompany
    .To = gOutlookEmail
    .CC = gOutlookEmailCC

    If intInclude = 1 Then
    If Not Dir(gPath & gOutlookAttachment & ".xlsx") = "" Then
    .Attachments.Add (gPath & gOutlookAttachment & ".xlsx")
    End If
    ElseIf intInclude = 2 Then
    If Not Dir(gOutlookAttachment) = "" Then
    .Attachments.Add (gOutlookAttachment)
    Kill gOutlookAttachment
    End If
    End If

    .Display

    End With

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 3 was moderated, I'm posting to trigger email notifications.

    Oops, too slow.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    what is the error? You haven't posted all the relevant code so it would just be guesswork as to what the problem is.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Folders don't have To, CC, Subject or Body properties. Those would be properties of an email item, which you haven't declared. I think that would be along the lines of
    Dim oItem As Object
    Set oItem = olApp.CreateItem(0)

    You're not using the namespace object so why declare it?
    Please post code within code tags (# button on posting toolbar) to maintain indentation and readability. You should include the whole procedure if it isn't ridiculously long because you leave us wondering where are all the variables coming from that don't seem to be declared.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Eug7 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2023
    Posts
    13
    Thank you Micron. I attempted to adapt the code from https://stackoverflow.com/questions/...ok-from-access

    The code I have in my DB now works perfectly buy again can't adapt to users with different Office versions/libraries.

    This is my Outlook handler module code:

    Option Compare Database
    Public WithEvents app As Outlook.Application
    Public WithEvents msg As Outlook.MailItem


    Private Sub Class_Initialize()


    Set app = CreateObject("Outlook.Application")
    Set msg = app.CreateItem(olMailItem)


    End Sub

    From there I command button send:

    Dim ol As OutlookHandler


    Public Function fnOutlookEmail()
    On Error GoTo Err_sbEmail


    '/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
    Set ol = New OutlookHandler


    With ol.msg
    .Subject = "some topic"
    .HTMLBody = "some explanation"
    .To = "outgoing email"
    .CC = "outgoing email CC"

    .Attachments.Add "(some attachement.xlsx)"
    .Display
    End With

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 8 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    After tens of thousands of posts everywhere I must have asked for this 5thousand times:
    Code:
    Please post code within code tags (# button on posting toolbar) to maintain indentation and readability.
    Wish I had 10 cents for every time. First time, I overlook and advise. Second time, I won't read it. Call me an old curmudgeon I guess.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Eug7 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2023
    Posts
    13
    Ok. Noob here. I can do what you ask. I see the # button but don't know how to use it. Just copy paste inside the []?

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Either select (highlight) all your pasted code and click that (#) or click # first then paste copied code in between the resulting tags, which look like
    Click image for larger version. 

Name:	CodeTags.jpg 
Views:	16 
Size:	2.1 KB 
ID:	49664
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    Eug7 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2023
    Posts
    13
    [Option Compare Database
    Public WithEvents app As Outlook.Application
    Public WithEvents msg As Outlook.MailItem


    Private Sub Class_Initialize()


    Set app = CreateObject("Outlook.Application")
    Set msg = app.CreateItem(olMailItem)


    End Sub][/CODE]


    [Dim ol As OutlookHandler


    Public Function fnOutlookEmail()
    On Error GoTo Err_sbEmail


    '/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
    Set ol = New OutlookHandler


    With ol.msg
    .Subject = "some topic"
    .HTMLBody = "some explanation"
    .To = "outgoing email"
    .CC = "outgoing email CC"

    .Attachments.Add "(some attachement.xlsx)"
    .Display
    End With][/CODE]

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You might want to review how your posts have actually been rendered by this site. Here's what I was hoping for:
    Code:
    Option Compare Database
    Public WithEvents app As Outlook.Application
    Public WithEvents msg As Outlook.MailItem
    
    
    Private Sub Class_Initialize()
    
    Set app = CreateObject("Outlook.Application")
    Set msg = app.CreateItem(olMailItem)
    
    End Sub
    
    Dim ol As OutlookHandler <<< this looks orphaned and I have no idea where to put it
    
    Public Function fnOutlookEmail()
    On Error GoTo Err_sbEmail
    
    '/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
    Set ol = New OutlookHandler
    
    With ol.msg
        .Subject = "some topic"
        .HTMLBody = "some explanation"
        .To = "outgoing email"
        .CC = "outgoing email CC"
        .Attachments.Add "(some attachement.xlsx)"
        .Display
    End With
    ' where is the end of this function ??
    That's all for me tonight. Maybe Vlad or someone else will pick this up - he's 3 time zones behind me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you show us (using the code tags) the complete code you say it works, including all\any module level declarations (at the top before any subs or functions)? We need to see both the OutlookHandler class module and the button click event that makes use of that along with any public variables or constants (which is what I assume your gSubject, gOutlookAttachment are).

    Changing to late binding should not be to hard, you need to replace the app specific declarations with Object and make sure you also replace the app specific constants (such as olFolderInbox) with their values (6 in this case):
    https://learn.microsoft.com/en-us/of...defaultfolders

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-06-2021, 06:34 AM
  2. Replies: 1
    Last Post: 01-04-2018, 07:39 AM
  3. Replies: 1
    Last Post: 05-15-2017, 11:40 AM
  4. Reference Libraries
    By dandoescode in forum Access
    Replies: 0
    Last Post: 06-07-2012, 07:07 AM
  5. Replies: 1
    Last Post: 06-09-2006, 03:55 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