Using Word Merge with Access via VBA - Error 91

Answered Using Word Merge with Access via VBA - Error 91

  • Tuesday, September 11, 2012 4:26 PM
     
     

    I have a function in MS Access that exports selected data to word using a word merge function.  This function works on multiple machines on both Access 2010 and 2007 without issue.  For some reason I have a clients machine where the function generates the following error message

    "Error 91 (Object variable or with block variable not set) in procedure MergeWord of Module WordCode"  

    If any of you have used Albert Kallal's function you will know the word merge function the error message is referring to.  Regardless, it really doesnt matter if you are familiar, the code appears to be failing at createobject or getobject as near as I can tell.  Which sort of tells me that Word is not installed, but the client insists that Word 2010 is installed.  

    So does anyone have any ideas as to what could be causing this issue.  Again, everything appears to be working on my end on multiple machines.

    Thanks,

All Replies

  • Tuesday, September 11, 2012 4:48 PM
     
     

    Can you post the code please?

    I suspect the code is specifying Word 2007 (Office 12)


    Chris Ward

  • Tuesday, September 11, 2012 4:55 PM
     
     

    Thanks for your help.

    It is late binding code.

          On Error Resume Next
          Set wordApp = GetObject(, "Word.Application")
          
          
          If Err.Number <> 0 Then
             Set wordApp = CreateObject("Word.Application")
          End If

  • Tuesday, September 11, 2012 6:01 PM
     
     

    Late binding would prevent the problem I was considering, that is good.

    This portion of your code has a syntax error (,

    Did you copy and paste your code or did you retype it. It's easier to analyze if you copy and paste.


    Chris Ward

  • Tuesday, September 11, 2012 6:13 PM
     
     

    I am not sure which portion has a syntax error.  Everything in the code works on my machines.  

    I copied and pasted this portion of the code, yes.

    Thanks,

  • Tuesday, September 11, 2012 6:14 PM
     
     
    Try removing the , to see if that fixes the issue.

    Chris Ward

  • Tuesday, September 11, 2012 6:27 PM
     
     

    Oh I see where you mean.  I have always had my late binding code use the comma.  

    Actually when I remove the comma from the GetObject portion I then get the syntax error and it just goes on to create the wordapplication. :)  

    So basically, regardless of how the getobject statement is written, if it errors, the next line just gets executed which would be to create a new word object.  

    Thanks,

    greg

  • Tuesday, September 11, 2012 6:28 PM
     
     

    I really dont think it comes down to a problem with the code itself...at least potentially...although still open to ideas.  I think it is some sort of configuration on the client's machine.  I just do not know what that configuration is to instruct them on how to fix it.

    thanks,

  • Tuesday, September 11, 2012 6:54 PM
     
     

    Are they using a compiled copy of the db?


    Chris Ward

  • Tuesday, September 11, 2012 7:13 PM
     
     

    Yes, compiled.  

    I have provided both an accdr and an accdb version as well without any change.

  • Tuesday, September 11, 2012 7:16 PM
     
     

    Did you test a compiled version on your machine as well?

    Sorry for asking, if this is silly but sometimes an accdb version will work on the designers machine and then the compiled will not.


    Chris Ward

  • Tuesday, September 11, 2012 7:24 PM
     
     

    No problem for silly questions...they need to be asked.  we all make little silly mistake at times thinking it is some greater problem. :)

    but yes, tested the exact version sent, and works without issue.

  • Tuesday, September 11, 2012 7:35 PM
     
     

    This portion of your code has a syntax error (,


    No it doesn't.

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

  • Tuesday, September 11, 2012 7:39 PM
     
     

    Having glanced down the thread and seen that you are using late binding -- early binding would have been the most likely cause -- it isn't clear what the problem is.  Could there be a conflict between 32-bit and 64-bit versions of Office?  Are they running 64-bit Windows?  Are the installations of Access and Word both 32-bit versions, or both 64-bit versions, or are they different?


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

  • Tuesday, September 11, 2012 7:43 PM
     
     

    Anything else?

    My only other thought so far is posted as a direct reply to the OP.

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

  • Tuesday, September 11, 2012 7:44 PM
     
     

    Having glanced down the thread and seen that you are using late binding -- early binding would have been the most likely cause -- it isn't clear what the problem is.  Could there be a conflict between 32-bit and 64-bit versions of Office?  Are they running 64-bit Windows?  Are the installations of Access and Word both 32-bit versions, or both 64-bit versions, or are they different?


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Hi Dirk,

    This is a very good thought.  I will proceed finding this out and is something I had overlooked.  Not sure if it would cause the issue, but worth checking off the list in any case.

    Thanks.

  • Tuesday, September 11, 2012 8:18 PM
     
     

    Oh I see where you mean.  I have always had my late binding code use the comma.  

    Actually when I remove the comma from the GetObject portion I then get the syntax error and it just goes on to create the wordapplication. :)  

    So basically, regardless of how the getobject statement is written, if it errors, the next line just gets executed which would be to create a new word object.  

    Thanks,

    greg


    This was educational for me as I hadn't seen this before. Thank you!

    Chris Ward

  • Tuesday, September 11, 2012 8:20 PM
     
     

    Glad to have educated you!  :)  I will let you know if the 32/64 bit is the issue. 

  • Thursday, September 13, 2012 6:50 AM
    Moderator
     
     

    Hi Voyagr12,

    Thanks for posting in the MSDN Forum.

    Did you solve this issue. If you have solved would you please share your solution here?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, September 13, 2012 7:46 PM
     
     

    I have not solved this issue yet.  I am still waiting on an answer from my client as to the 64bit/32bit version of Word they are using with regards to Dirk's comment about the possibility of a conflict between 64/32 bit versions.  So still waiting on that and still open to additional ideas in the interim.  Tom do you have any?

    Thanks,

  • Friday, September 14, 2012 1:54 PM
     
     

    Just an update for anyone who has anything else to contribute.

    My client is using the 32 bit versions so that is not the issue because I to am using 32 bit.  

    Any other ideas?  

  • Friday, September 14, 2012 2:09 PM
     
     

    Good Morning Voyagr12,

    I would like to see if I can recreate the issue. Can you post the complete code so I can try it?


    Chris Ward

  • Friday, September 14, 2012 2:13 PM
     
     

    Good Morning Voyagr12,

    I would like to see if I can recreate the issue. Can you post the complete code so I can try it?


    Chris Ward

    Here is the test application I had created to help me diagnose and troubleshoot the issue.  This very simple test application still did the same thing on the client's computer but works well on my pcs.  I am currently in the process of setting up a few virtual machines myself with varying degrees of configurations to see if I can replicate the issue....so far no go...but still trying.

    Actually I just realized I am not sure how to attach a file.  I will put one up elsewhere and give you a link.

    thanks,

  • Friday, September 14, 2012 2:32 PM
     
     

    Here is a link to the zip file containing the application.

    Test Application

  • Friday, September 14, 2012 3:04 PM
     
     

    If you take a look at the test application, the client is having the code fail within the MergeWord function between line 545 and line 566.  The reason I know this is because I have received screen shots of the progress bar and the progress bar shows that line 545 executed but line 566 has not.  And this also makes sense because in between those two lines are where the wordApp variable is being set via the CreateObject/GetObject.  So basically it appears that for some reason the Access app can not create the word instance or get a current instance even though Word is installed.  

    Thanks,

  • Friday, September 14, 2012 3:08 PM
     
     Answered

    Here is a link to the zip file containing the application.

    Test Application

    It works fine for me.

    Here's a thought:  maybe the user has a "Click2Run" version of Word installed.  I'm pretty sure the code won't work in that case.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked As Answer by Voyagr12 Friday, September 14, 2012 4:01 PM
    •  
  • Friday, September 14, 2012 3:11 PM
     
     

    Right, it works everywhere just fine. :)  except for my client. :)...

    the "Click2Run" may be a good idea.  Now, the question is, how do I test that hypothesis?  I wonder if I can download a version like that?  Off to check

    Thank you all for the help so far!

  • Friday, September 14, 2012 3:26 PM
     
     

    Hi Dirk,

    The more I think about your suggestion the more it makes sense.  I have found a download for the starter edition...hopefully it is not to riddled with viruses and the such as it is not from microsoft... I will be installing on a clean virtual machine shortly to test.  I will let you know the results.

    Thanks,

  • Friday, September 14, 2012 3:29 PM
     
     

    Right, it works everywhere just fine. :)  except for my client. :)...

    the "Click2Run" may be a good idea.  Now, the question is, how do I test that hypothesis?  I wonder if I can download a version like that?  Off to check

    I vaguely recall running into this before, and I'm also finding some confirmation online that you can't automate Click2Run applications from outside those applications.  Se, for example, these threads:

        http://stackoverflow.com/questions/3372394/is-it-possible-to-automate-a-click-to-run-application

        http://social.msdn.microsoft.com/Forums/is/visualfoxprogeneral/thread/c720813f-cf15-4e26-b205-e1d2530d0faf

    So this is at least a good candidate for the source of this problem.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

  • Friday, September 14, 2012 4:00 PM
     
     

    Here is the latest.  Still waiting on a response from my client but I have installed the starter edition on a clean virtual machine and indeed, the application would not use word.  

    Totally makes sense.  Thanks so much for the help, it is greatly appreciated.  I am not sure if I would have ever discovered this.

    Have a great day!

  • Friday, September 14, 2012 4:05 PM
     
     
    Glad you have your answer.

    Chris Ward

  • Friday, September 14, 2012 5:12 PM
     
     

    Well, although Dirk's suggestion could prove to be the answer in certain situations, it appears that it is not in this particular case.  The client has told me that they do not have the starter pack.  I have scheduled a screenshare with them to see if I can see anything else.  Perhaps they do have the starter pack just not aware of it?  who knows.

    I will keep the post updated on any new information.

    thanks,

  • Friday, September 14, 2012 6:39 PM
     
     

    Well, although Dirk's suggestion could prove to be the answer in certain situations, it appears that it is not in this particular case.  The client has told me that they do not have the starter pack.  I have scheduled a screenshare with them to see if I can see anything else.  Perhaps they do have the starter pack just not aware of it?  who knows.

    I don't know if you can rule out Click2Run just yet.  The starter pack isn't the only version of Office that uses Click2Run.  It's an available installation option for the "Office Home and Student 2010" and the "Office Home and Business 2010" versions.

    Alternatively, I would think that Office 365 might have a similar issue, though I don't know if it is the same as Click2Run or not.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html