CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2000
    Location
    Maryland
    Posts
    181

    How do I keep MS Word open when opened by MS Access

    How do I keep MS Word open when opened by MS Access

    I am writing an MS Access application. This code snippet just opens MS world and closes immediately. This is not what I want. I want to be able to leave it open long enough to edit it.

    Dim objWord As Word.Application



    Function OpenAWord_Maybenot(wordDocStr As String)

    If TypeName(objWord) <> "Application" Then

    'Start Microsoft Word 97.
    Set objWord = CreateObject("Word.Application")

    objWord.Visible = True
    objWord.Documents.Open (wordDocStr)


    'Quit Microsoft Word and release the object variable.
    objWord.Quit
    Set objWord = Nothing

    End If

    End Function

  2. #2
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    The problem is in your function, you open word and you close it as soon as it is open. Those lines closes word:

    'Quit Microsoft Word and release the object variable.
    objWord.Quit
    Set objWord = Nothing

    When word closes, the document also closes, so don't close word until you're done with any documents you opened.

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured