Results 1 to 9 of 9

Function to load reference library - Not seeing something in function

  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Function to load reference library - Not seeing something in function

    I call this function before I run the code that uses outlook to email - however it won't add the library. Outside of the function this code works fine, in a public function in a module it won't work...



    Code:
    'adds the outlook library
    Public Function addOutlookLibrary() As Boolean
    
    
    Dim ref As Object
    Dim OutlookPath As String
    dim refexists  as boolean
    OutlookPath = "C:\Program Files (x86)\Microsoft Office\Office14\MSOUTL.OLB"
    
    
    
    
            If Len(Dir(OutlookPath)) = 0 Then
            MsgBox "You are missing the required library, you can't use this form to send emails"
            addOutlookLibrary = False
            
            Exit Function
            
            Else
            
            refexists = False
                  
                 For Each ref In References
                 Debug.Print ref.Name
                     If ref.Name = "Outlook" Then
                         refexists = True
                     End If
                 Next
                 
                If refexists = False Then
                Access.References.AddFromFile (OutlookPath)
                End If
            
            addOutlookLibrary = True
            End If
    
    
    End Function

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    7,798
    Do you have the OUTLOOK OBJECT library , manually loaded via VBE menu, TOOLS, REFERENCES, outlook object lib?

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ranman256 View Post
    Do you have the OUTLOOK OBJECT library , manually loaded via VBE menu, TOOLS, REFERENCES, outlook object lib?
    No. That's the point of the function. I have one to add function and one to remove.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    2,908
    I can't remember ever having occasion to do this kind of thing, but for some reason have an archived blurb on it from somewhere in the distant past. According to this, in order to dynamically load a Reference Library you first have to manually add a reference named

    Microsoft Visual Basic for Applications Extensibility

    Once that is loaded, you can then use code to dynamically load other libraries. In other words, it's a Reference needed to load References! Is that the Redmond Way, or what?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    I can't remember ever having occasion to do this kind of thing, but for some reason have an archived blurb on it from somewhere in the distant past. According to this, in order to dynamically load a Reference Library you first have to manually add a reference named

    Microsoft Visual Basic for Applications Extensibility

    Once that is loaded, you can then use code to dynamically load other libraries. In other words, it's a Reference needed to load References! Is that the Redmond Way, or what?

    Linq ;0)>
    it works normally for me within a regular event however loading the function in the event containing the same code does not work...

    I was hoping just to have it on hand as a function so that it would save typing it out each time I want to bring it into play

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,566
    Did you try it as a non-event Sub instead of Function? Although really don't know why that would make a difference.

    I just tested a Sub and it doesn't find the MSOUTL.OLB file. Because mine is in Program Files folder (the 64-bit OS version). Works. So I backtracked and tried the function. That works also.

    How are you calling the function?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    8,525
    I found some code to add/remove references on-the-fly:

    http://stackoverflow.com/questions/5...rogramatically


    By Doug Steele (good article)
    Access Reference Problems
    http://www.accessmvp.com/djsteele/ac...nceerrors.html


    https://www.accessforums.net/program...ces-26064.html
    see post # 13
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Thanks guys for your help - I narrowed down the problem

    I was the line

    Code:
    Access.References.AddFromFile (OutlookPath)
    I replaced it with

    Code:
    References.AddFromFile (OutlookPath)
    I don't know why I had access in front of it....

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,566
    Odd, I used your code and it ran fine for me. But glad you got it resolved.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 02-25-2014, 03:11 PM
  2. Runtime Access & Outlook library reference
    By Ruegen in forum Access
    Replies: 16
    Last Post: 12-10-2013, 05:26 PM
  3. Replies: 1
    Last Post: 03-22-2013, 03:33 AM
  4. MU File Reference Library
    By dandoescode in forum Access
    Replies: 17
    Last Post: 06-20-2012, 12:40 PM
  5. Load images in access using iif function?
    By sureshfina in forum Forms
    Replies: 1
    Last Post: 12-22-2009, 11:05 AM

Posting Permissions

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