Results 1 to 3 of 3
  1. #1
    graffjohn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Location
    dc
    Posts
    1

    vba code to populat word template in Access 2010

    The following code worked fine for 5 years in MS Access 2003. My company converted to MS Office 2010 and the VBA MS Access code is now getting an error

    The code is populating an MS Word template (.dot) with fields from a form. the line in BOLDED RED is giving the following error

    "application-defined or object-defined error:"

    So, I need the changes to the code so that VBA code will be compatable with MS Access 2010 and MS Word 2010

    any insights would be appreciated

    Thanks,
    John

    Here's the VBA code

    '************************
    ' Print a general Letter
    '************************


    Dim objWord As Object
    Dim HoldTemplateLocation As String
    Dim Direc As String
    Set Dbs = CurrentDb


    Direc = "C:\MSWord_Lletters\"



    ' Open Microsoft Word

    Set objWord = CreateObject("Word.Application")

    objWord.Visible = True

    objWord.Documents.Add Direc & "General letter.dot"



    objWord.ActiveDocument.Bookmarks("X1ToodayName").R ange.Text = Forms![LookUpData]![ToodayName]

    objWord.ActiveDocument.Bookmarks("X2ToodayDate").R ange.Text = Forms![LookUpData]![ToodayDate]


    objWord.ActiveDocument.Bookmarks("X9Dearr").Range. Text = Forms![LookUpData]![AcctNum]
    Last edited by graffjohn; 06-11-2011 at 12:21 PM. Reason: spelling error

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    hmmm...

    well the pool of info that the compiler is catching is:

    .DOCUMENTS collection
    .ADD method

    so it's one of those two obviously. Perhaps .dot templates are allowed in the documents collection?

    but looking at it closer, you are SURE this is right??
    Code:
    Direc = "C:\MSWord_Lletters\"
    looks like there's 2 L's in your dir name?? upper and lower cases?? Perhaps some nice employee messed it up?

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The following code worked fine for 5 years in MS Access 2003. My company converted to MS Office 2010 and the VBA MS Access code is now getting an error
    1) Do you have these two lines at the top of every code page?
    Code:
    Option Compare Database
    Option Explicit
    2) Does the code compile without errors?

    3) You might also check for broken (VBA) references. When you change versions of Access (or Office), the names of some of the dll's change. In A2K3, the reference library for Word is "Microsoft Word 11.0 Object Library"; in A2K10, the reference name might be "Microsoft Word 14.0 Object Library". Most reference names do not get updated when you convert from one version to another, which results in broken references.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-20-2011, 07:42 AM
  2. Replies: 1
    Last Post: 03-18-2011, 03:22 PM
  3. Code does not work in 64 Bit Access 2010
    By mwolfod in forum Programming
    Replies: 26
    Last Post: 12-12-2010, 04:39 PM
  4. Word.Basic ToolsSpelling won't work in Access 2010
    By stav.kaufman in forum Programming
    Replies: 6
    Last Post: 11-23-2010, 08:44 AM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM

Tags for this Thread

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