Results 1 to 8 of 8
  1. #1
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82

    Managing references through code

    Hello,



    Our organization is currently moving from Windows 7 to Windows 10 and from Office 2013 to Office 2016. It is going to take some time, so there will be users out there using different versions of everything.

    This has caused an issue in an Access DB I have created, specifically when it comes to three libraries: Word Object Library, Outlook Object Library and MS Office Library.

    I copied v.16 libraries and put them into my DB folder and tried referencing them through VBA. It works sometimes, but not all the time. When a user first opens the DB since the new code, they still get missing libraries. If I go on their computer and unselect the libraries, then reopen the DB, it works.

    Important to note: I cannot convert my database to an executable.... I have no idea why. The users use the .accdb file to access it with limitations. Ideally, I could pick my references and roll them up into one package, but that doesn't seem to be an option. I believe it has something to do with our IT policies.

    It is not feasible for me to do this on everyone's computer/account, so I'm hoping for ideas from the forum.

    Let me know if I need to be more specific with the problem!

    Thanks,

    Scott

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The best way to handle differing versions in my opinion is to use late binding so you don't need references. Here's a Word example:

    https://www.devhut.net/2010/09/03/vb...-late-binding/
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  4. #4
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82
    Trying to late bind with the following code, but it gives me an error when running saying that wdFormLetters is not a defined variable. I'm guessing that with late binding, referencing properties is a no-go? It's not processing any of the code in this sub. It throws the error right away.

    Here is a snippet of the code:

    Code:
            Dim oWord As Object
            Dim oWdoc As Object
            
            Set oWord = CreateObject("Word.Application")
            
        Dim wdInputName As String
        Dim wdOutputName As String
        Dim outFileName As String
        Const msoFileDialogFilePicker As Long = 3
        Dim objDialog As Object
        
        On Error GoTo PROC_ERR
        
        ' Set Template Path
        '------------------------------------------------
        Set objDialog = Application.FileDialog(msoFileDialogFilePicker)
        With objDialog
            .AllowMultiSelect = False
            .InitialFileName = CurrentProject.Path & "\MailMergeDocs\"
            .Show
            If .SelectedItems.Count = 0 Then
                MsgBox "No file selected."
                Exit Sub
            Else
                wdInputName = .SelectedItems(1)
            End If
        End With
     
        'Set oWord = New Word.Application
        Set oWdoc = oWord.Documents.Open(wdInputName)
     
        ' Start mail merge
        '------------------------------------------------
        With oWdoc.MailMerge
            .MainDocumentType = wdFormLetters
            .OpenDataSource _
                Name:=CurrentProject.FullName, _
                AddToRecentFiles:=False, _
                LinkToSource:=True, _
                Connection:="TABLE tblMailMergeTMP", _
                SQLStatement:="SELECT * FROM [tblMailMergeTMP]"
            .Destination = wdSendToEmail
            .MailAsAttachment = False
            .MailFormat = wdMailFormatHTML
            .MailAddressFieldName = "UserID"
            .MailSubject = "Joining Instructions for: " & cbxCourse.Column(0)
            
            .Execute Pause:=False
        End With
     
        ' Hide Word During Merge
        '------------------------------------------------
        oWord.Visible = False
      
        ' Quit Word to Save Memory
        '------------------------------------------------
        oWord.Quit savechanges:=False
     
        ' Clean up memory
        '------------------------------------------------
        Set oWord = Nothing
        Set oWdoc = Nothing

  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,518
    That is a downside to using late binding. You can either look up the numeric equivalent, or what many of us do is use early binding to start, set a breakpoint and examine that constant at runtime, which will show you the numeric equivalent. Your code would then look like:

    .MainDocumentType = 123

    where 123 is the value it's expecting.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    That one is 0, here's a reference:

    https://docs.microsoft.com/en-us/pre...3(v=office.11)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82
    Awesome! Thanks for the help. Slowly piecing this thing together!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Managing Attachments
    By snowboarder234 in forum Database Design
    Replies: 1
    Last Post: 07-27-2016, 07:48 AM
  2. Replies: 2
    Last Post: 04-18-2016, 01:40 PM
  3. Managing a CPR class
    By DiPietro14 in forum General Chat
    Replies: 1
    Last Post: 02-06-2012, 06:02 PM
  4. Managing Inventory in Access
    By bushkanaka86 in forum Access
    Replies: 1
    Last Post: 11-25-2011, 08:31 PM
  5. Missing references and running code at startup
    By springrider in forum Programming
    Replies: 1
    Last Post: 01-09-2011, 09:47 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