Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    missing reference to 'MSWORD.OLB'

    My references show only microsoft 16 options.

    The machine im trying to put the database on can only reference microsoft 15 library.

    I cant select this library on my machine as its not there. The other machine is using runtime so I cant change it there either.

    Any suggestions?

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    The code is shown here.

    I remmember resolving this issue a few years ago using late binding. Its been that long I am clueless now. (I am researching but any hints appreciated)
    Code:
    private Sub Command7_Click()
     
    Dim FSO
    Dim sFile As String
     
    Dim sDFolder As String
    Dim sNewFile  As String
    Dim answer As Integer
     
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "update_RAMS_issue", acViewNormal, acEdit
     
    If Nz(Me.lstFileList, "") = "" Then
         MsgBox "pick a template."
         Me.Refresh
         Me.Requery
        
         Exit Sub
    End If
     
     
     
     
    'File Name to Copy
    sFile = Me.lstFileList
     
    ' New File Name
    sNewFile = "RAM_" & Me.Site_Name & "_" & Me.Site_ID & "_" & Me.RAMS_ISSUE & ".docx"
     
    'destination folder path
    sDFolder = "\\SERVER\general\RAMS\RAM_RAMS\" & sNewFile
     
    Application.Echo False
     
    '-------msgbox for rams-----
     
    answer = MsgBox("Make RAMS for " & Me.Site_Name & "?", vbYesNo + vbQuestion, "Empty Sheet")
    If answer = vbYes Then
     
    Else
        Exit Sub
    End If
       
    '-------msgbox for rams end-----
     
    'Create Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
     
    'Checking If File Is Located in the Source Folder
    If Not FSO.FileExists(sFile) Then
        MsgBox "Specified File Not Found", vbInformation, "Not Found"
       
    'Copying If the Same File is Not Located in the Destination Folder
    ElseIf Not FSO.FileExists(sDFolder) Then
        FSO.CopyFile (sFile), sDFolder, True
     
    Else
        MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
        Exit Sub
    End If
     
    '-----------------CREATE FILE END-----------------
    '-----------------AMMEND FILE-----------------
     
     
        '-----------------Set up word document to use recordset ------------------
        Dim wrdApp As New Word.Application
        Dim wrdDoc As Word.Document
        Dim filepath As String
        Dim docFile As String
        Dim rst As DAO.Recordset
        '-----------------Set up word document to use recordset end------------------
     
     
        '                    --------------------------
     
     
        '-----------------define bookmark variables as range -----------------
     
        Dim Date_Compiled As Word.Bookmarks
        Dim Doc_No As Word.Bookmarks
        Dim hospital_details As Word.Bookmarks
        Dim site_details As Word.Bookmarks
        Dim Site_Name1 As Word.Bookmarks
        Dim Site_Name_Postcode As Word.Bookmarks
        Dim User As Word.Bookmarks
        Dim User_Long As Word.Bookmarks
       
        Dim Date_Compiled1 As Word.Bookmarks
        Dim Date_Compiled2 As Word.Bookmarks
        Dim Date_Compiled3 As Word.Bookmarks
        Dim User_Long_title As Word.Bookmarks
        Dim site_details1 As Word.Bookmarks
        Dim Doc_No1 As Word.Bookmarks
        '-----------------define bookmark variables as range end------------------
     
     
     
     
        '------------------ define query -----------------------------
        Dim db As Database
        Dim sSql As String
     
     
        Set db = CurrentDb
     
     
        sSql = "SELECT SiteT.Site_ID, SiteT.Site_Name, SiteT.Asset_Type, SiteT.Address_1, SiteT.Address_2, SiteT.Address_3, SiteT.Postcode, ClientT.Company_Name, ClientT.Company_ID, HospitalT.Hospital_Name, HospitalT.Hospital_Postcode, HospitalT.Hospital_Address, HospitalT.Hospital_Telephone, SiteT.lat, SiteT.long, SiteT.Rams_Issue "
        sSql = sSql & "FROM HospitalT INNER JOIN (ClientT INNER JOIN SiteT ON ClientT.Company_ID = SiteT.Site_Owner) ON HospitalT.Hospital_ID = SiteT.Hospital_ID "
        sSql = sSql & "WHERE [SiteT].[Site_ID] = " & Me.Site_ID & " "
        sSql = sSql & "ORDER BY SiteT.Site_Name;"
     
     
        Set rst = db.OpenRecordset(sSql)
     
     
     
        filepath = sDFolder
     
     
     
     
     
     
     
        Set wrdApp = CreateObject("Word.Application")
        wrdApp.Visible = False
     
     
        Set wrdDoc = wrdApp.Documents.Open(filepath)
     
     
        With wrdDoc
     
            wrdApp.ActiveDocument.Bookmarks("Date_Compiled").Select
            wrdApp.Selection.Text = Date
     
            wrdApp.ActiveDocument.Bookmarks("Doc_No").Select
            wrdApp.Selection.Text = rst("Site_ID") & "_" & rst("Rams_Issue")
     
            wrdApp.ActiveDocument.Bookmarks("hospital_details").Select
            wrdApp.Selection.Text = rst("Hospital_Name") & vbCrLf & rst("Hospital_Address") & vbCrLf & rst("Hospital_Postcode") & vbCrLf & rst("Hospital_Telephone")
     
            wrdApp.ActiveDocument.Bookmarks("site_details").Select
            wrdApp.Selection.Text = rst("Site_Name") & vbCrLf & rst("Address_1") & vbCrLf & rst("Address_2") & vbCrLf & rst("Address_3") & vbCrLf & rst("Postcode")
     
            wrdApp.ActiveDocument.Bookmarks("Site_Name1").Select
            wrdApp.Selection.Text = rst("Site_Name")
     
            wrdApp.ActiveDocument.Bookmarks("Site_Name_Postcode").Select
            wrdApp.Selection.Text = rst("Site_Name") & vbCrLf & rst("Postcode")
     
            wrdApp.ActiveDocument.Bookmarks("User").Select
            wrdApp.Selection.Text = "PB"
     
            wrdApp.ActiveDocument.Bookmarks("User_Long").Select
            wrdApp.Selection.Text = "test"
     
            wrdApp.ActiveDocument.Bookmarks("User_Long_title").Select
            wrdApp.Selection.Text = "test"
           
            wrdApp.ActiveDocument.Bookmarks("Date_Compiled1").Select
            wrdApp.Selection.Text = Date
           
            wrdApp.ActiveDocument.Bookmarks("Date_Compiled3").Select
            wrdApp.Selection.Text = Date
           
            'wrdApp.ActiveDocument.Bookmarks("Date_Compiled2").Select
            'wrdApp.Selection.Text = Date
           
            wrdApp.ActiveDocument.Bookmarks("Doc_No1").Select
            wrdApp.Selection.Text = rst("Site_ID") & "_" & rst("Rams_Issue")
           
            wrdApp.ActiveDocument.Bookmarks("Doc_No2").Select
            wrdApp.Selection.Text = rst("Site_ID") & "_" & rst("Rams_Issue")
     
            wrdApp.ActiveDocument.Bookmarks("site_details1").Select
            wrdApp.Selection.Text = rst("Site_Name") & vbCrLf & rst("Address_1") & vbCrLf & rst("Address_2") & vbCrLf & rst("Address_3") & vbCrLf & rst("Postcode")
        
     
    wrdApp.ActiveDocument.Save
    wrdApp.ActiveDocument.Close
     
        End With
        Set rst = Nothing
       
    Application.Echo True
    DoCmd.SetWarnings True
     
     
     MsgBox "RAMS are saved: " & sDFolder, vbInformation, "Done!"
     
    Me.Refresh
    Me.Requery
     
     
    '---------------------------------------------------RISKS-----------------------------------------
     
    Dim xl As Object
     
    'Step 1:  Start Excel, then open the target workbook.
       Set xl = CreateObject("Excel.Application")
        xl.Workbooks.Open ("\\SERVER\general\Documents\!Management\VBA_Templates_do_not_modify\HAZARDS\HAZARDS.xlsm")
       
        '------------------------------paste path to excel-----------------------------------
       
     
      
        xl.worksheets("PasteSpecial").Activate
        xl.Range("i1").Value = sNewFile
       
        '------------------------------paste path to excel-----------------------------------
     
     
    'Step 2:  Make Excel visible
       xl.Visible = True
     
    'Step 3:  Run the target macro
       xl.Run "ThisWorkbook.BetterExcelDataToWord"
     
    'Step 4:  Close and save the workbook, then close Excel
       xl.ActiveWorkbook.Close (True)
        xl.Quit
     
    'Step 5:  Memory Clean up.
       Set xl = Nothing
     
     
    '---------------------------------------------------RISKS-----------------------------------------
     
    End Sub

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    I had this problem. To deliver the app to that user, you must remove the Word reference.
    then put in code to load the 'Word x.x' reference on their PC.

    I had an autoexec macro that
    step 1: run code to load reference
    step 2: load main menu form


    Code:
    public function AddWordRef()
      on error resume next
        Application.References.AddFromGuid "{00020905-0000-0000-C000-000000000046}", 1, 0
    end function
    be sure to check their PC for the correct Guid.

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thank you ranman. I think i know what you're saying but let me check.

    Remove the reference to word from tools>references.

    I can leave the code as it is?

    That would be great if so.

    Im not even sure what a GUID is but im sure thats simple enought to find out and check.

    Thanks!

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Ranman hopefully you can help me out,

    I know what a GUID is now but I cant see how to find it anywhere. Could you point me in the right direction?

  6. #6
    Super Mario is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Aug 2018
    Posts
    12

  7. #7
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thank you Mario. Ill look into it.

  8. #8
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I spent a few hours yesterday and this morning trying to impliment that and had all sorts of problems. (had it partialy working).

    Anyway, the code I posted was a mess, it didn't even need to define the bookmarks as it was already using late binding in parts. I only needed to delete the bookmark references and change to this:

    Code:
     Dim wrdApp As Object
        Dim wrdDoc As Object
    It's all working now.

    Your suggestions have forced me to understand more about several things, so I appreciate the help.

    Cheers.

  9. #9
    Super Mario is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Aug 2018
    Posts
    12
    Homegrownandy:

    I am glad that my suggestion helped you to find a solution. I was considering Late Binding before I decided to try assigning references on the fly. But my application is very complex and have thousands of lines of code; doing late binding would entail scrubbing the existing code and making changes. I was afraid of possible side effects if I changed the code from early binding to late binding. My solution would not be the best choice at early development of my application; but at this stage, it was the less risky patch.

    Thank you

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Super Mario
    You just raised a good point which I forgot to mention in the other thread.

    Like many developers, I often use early binding during development in order to use intellisense, then swop to late binding at the end so I can remove version specific references to Excel, Outlook, Word as well as remove references which may not be available on all machines.

    Having done that on numerous occasions, I thought it worth mentioning that it really isn't a big task.
    Usually just remove one reference, compile and fix errors one by one.
    Repeat for each reference you want to remove in turn.
    In almost all cases, just redefining variables as Object may be all you need to do.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Super Mario is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Aug 2018
    Posts
    12
    Since my application is a "work in progress", I don't want to give up intellisense yet. So I will stick to early binding and assigning references on-the-fly for the foreseeable future.

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

Similar Threads

  1. Replies: 4
    Last Post: 04-06-2016, 07:16 AM
  2. Missing Reference dll files
    By YaseenIskaf in forum Programming
    Replies: 2
    Last Post: 08-22-2012, 10:21 AM
  3. Missing reference problem
    By YaseenIskaf in forum Programming
    Replies: 0
    Last Post: 08-21-2012, 12:22 PM
  4. Missing Reference
    By lrobbo314 in forum Access
    Replies: 1
    Last Post: 04-20-2012, 07:13 PM
  5. Missing Reference
    By teebumble in forum Access
    Replies: 17
    Last Post: 10-05-2011, 01:35 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