Consulting

Results 1 to 11 of 11

Thread: Access VBA to RESET Code

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location

    Access VBA to RESET Code

    I'm using Access to open a Word Document using:
    HTML Code:
    Set WdDoc = AppWd.Documents.open(....
    to open a word document which works fine on the first time it is opened but if the document is closed and the code is re-ran it gives the following error:

    "Run-time error '462'
    "The remote server machine does not exist or is unavailable"

    I believe the problem is that Access still thinks Word is open because the object still exists.

    I've tried wdDoc.Close and Set AppWd to nothing but that causes problems trying to run it again.

    What does work is to catch the error and when the debug window pops up click "end" or "reset" the code run. Any ideas on how to fix this problem?

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    This is the code that I use to finish the VBA after sending the data to word,

    m_objDoc.SaveAs Filename:=newname
    m_objDoc.Close
    m_objWord.Quit
    ' clean up
    Set m_objDoc = Nothing
    Set m_objWord = Nothing

    Note it closes the word doc and quits word before setting the variables to nothing, you could try that for your variables.

  3. #3
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Thank you for the reply. Is there away of ending the script and keeping the Word document open? The user most likely will need to use the database while referring to the document.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Well it would appear that it is keeping the word doc open that is causing your problem, so I am not sure how to resolve that.
    I suppose that you could close it all down and then try re-opening just for viewing purposes.
    I would try the closing it all down first to see if it resolves your original problem.

  5. #5
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    I guess what I really want to do is open a Word document without creating an object. Or to be able to close the object without closing the document.

  6. #6
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    You can open them manually first, but I am not sure if that is what you mean.

  7. #7
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    I found the following:

    HTML Code:
    Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True
    Which seems to be what I was looking for.

  8. #8
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location

    Does it prevent the error?

  9. #9
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    It does. Since I'm not using an object it isn't an issue. You are right about using .quit which it might be the only way to prevent the error.

    This error has been a pain for me for a very long time. Users sometimes will close Word (from Word) which doesn't give the Access code the chance to kill the object. Is there a way that I could have code running in the background and if it detects that Word was closed that it will then kill the object that was created?

  10. #10
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    You could have a form open in invisible mode and set it's timer to test if there is a doc open and if it is not close & quit the object.

  11. #11
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    That is a good idea. Didn't think of that - I'll give it a shot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •