none
Compile Error in hidden module: ThisDocument.. This error commonly occurs when code is incompatible with the version, platform or architecture of this application RRS feed

  • Question

  • I have an Access Database that exports to data to Word. On a few machines users are getting the following error

    Compile error in hidden module: This document. This error commonly occurs when code is incompatible with the version, platform or architecture of this application.

    The users (2 so far) are both running Office 2010 - 32-bit. I can copy their database and run it fine on my computer which is also running Office 2010.

    The error occurs when Access data is being exported to Microsoft word templates and always happens when code gets to: 

    x = wrdDoc.CreateNCRow(ViolationStr)

     If Not rstIAO.EOF Then
          If Not NewTabSet Then
            x = wrdDoc.CreateNCRow(ViolationStr) ' error occurs here on select machines
          End If
          wrdDoc.FormFields("IAO" + ViolationStr).Result = Mid(rstIAO("NC").Value, 1, 2) + "-" + Mid(rstIAO("NC").Value, 3)
          wrdDoc.FormFields("IAOType" + ViolationStr).Result = rstIAO("IAOType").Value
          rstIAO.MoveNext
        End If

    I thought it would be references and I compared the references on my computer to the users and nothing is said to be missing. They both have:

    • VBA
    • Microsoft Access 14.0 Object
    • OLE Automation
    • DAO 3.6
    • Microsoft ActiveX data objects 2.5
    • Outlook 14 object
    • Word 14 object

    Any help would be greatly appreciated. I am not sure what direction to take from here especially since its a random issue.



    jim neal

    Friday, June 7, 2013 7:44 PM

Answers

  • Hi Jim

    The module ThisDocument is contained within Word documents. It's a class representation of the document, itself, and reflects/exposes a number of properties relevant to the document. In addition, it provides a way to work with events on the document, such as Open and New and provides events for activeX and content controls on the document surface.

    So the first thing I'd be interested in is the document represented by the object wrdDoc. From your code, I take it the document has form fields. Any ActiveX controls and/or content controls that are linked to code?

    The problem could conceivably also be in the users' Normal.dotm template(s) or in a Word template loaded as an add-in that's somehow conflicting with your program. And since you can't reproduce the problem at your end, this is something you should look into more closely.

    How does your Access program intiate automation of the Word application on a user's machine?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 11, 2013 6:37 PM
    Moderator

All replies

  • As mentioned in your post, the error occurs on  x = wrdDoc.CreateNCRow(ViolationStr).

    Since we could not see where you defined CreateNCRow method, we're not able to infer the possible reasons.

    It's not the code here that causes the error but the implementation of CreateNCRow method, I suppose.


    Regards,
    Fermin
    What's life without whimsy?

    Tuesday, June 11, 2013 3:41 PM
  • Sub CreateNCRow(ItemNum As String)
    Dim ffield As FormField
      
      ActiveDocument.Unprotect "garfield"
      Selection.GoTo What:=wdGoToBookmark, Name:="NC"
      ActiveDocument.Bookmarks("NC").Delete
      Selection.MoveRight Unit:=wdCell, Count:=10
      ActiveDocument.Bookmarks.Add Name:="NC"
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "NC" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "CO" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "COType" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "INC" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "INCType" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "IAO" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "IAOType" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "MOD" + ItemNum
        .Enabled = False
      End With
      Selection.MoveRight Unit:=wdCell
      
      Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With ffield
        .Name = "ModType" + ItemNum
        .Enabled = False
      End With
      ActiveDocument.Protect wdAllowOnlyFormFields, NoReset, "garfield"
    End Sub


    jim neal

    Tuesday, June 11, 2013 4:04 PM
  • Hi Jim

    The module ThisDocument is contained within Word documents. It's a class representation of the document, itself, and reflects/exposes a number of properties relevant to the document. In addition, it provides a way to work with events on the document, such as Open and New and provides events for activeX and content controls on the document surface.

    So the first thing I'd be interested in is the document represented by the object wrdDoc. From your code, I take it the document has form fields. Any ActiveX controls and/or content controls that are linked to code?

    The problem could conceivably also be in the users' Normal.dotm template(s) or in a Word template loaded as an add-in that's somehow conflicting with your program. And since you can't reproduce the problem at your end, this is something you should look into more closely.

    How does your Access program intiate automation of the Word application on a user's machine?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 11, 2013 6:37 PM
    Moderator
  • The issue causing the error was this line:

    ActiveDocument.Protect wdAllowOnlyFormFields, NoReset, "pass"

    I changed it to the following and it worked. I do not know enough about vba to understand why it worked though

    ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True, Password:="pass"


    jim neal


    • Edited by JamesLNeal Monday, June 24, 2013 2:14 PM
    Monday, June 24, 2013 11:47 AM
  • Hi James

    The reason your original line of code did not work is that you didn't pass the VALUE of the second parameter (at least, I assume you never defined a variable named Reset anywhere in your project?). If you had done the following, it probably would have worked:

    ActiveDocument.Protect wdAllowOnlyFormFields, True, "garfield"

    Can you see the difference? Apparently, VBA decided you were giving the parameter name and wanting to use the default value, which is False.

    It would be very important for you to activate the checkbox "Require Variable declaration" in Tools/Options/Editor. That will write the statement Option Explicit at the top of every new module you create. (And you should type it at the top of your existing modules). Then, if you accidently use the parameter name instead of a value (or mistype a variable name) you'll get a warning. This may seem like more work, at first, but it will save you lots of time and frustration in the long run... 


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, June 24, 2013 3:41 PM
    Moderator