Open Word Doc From Access

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Open Word Doc From Access

Post by Leesha »

Hi,
I'm using the code below to open a Word Doc from Access. The code works however Word opens in the background and I get complaints that it isn't working when in fact it is open in their task bar. Is there a way to change the code so the document opens on top of Access so to speak or is there better code to use?
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78370
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Word Doc From Access

Post by HansV »

"the code below"?
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Open Word Doc From Access

Post by Leesha »

I really need to get some sleep!

Code: Select all

    Dim LWordDoc As String
   Dim oApp As Object

   'Path to the word document
   LWordDoc = "C:\Trinity Solutions\TrinitySolutionsDatabaseFiles\Directions\ImportPersoanlClientData\Import Personal Data Directions.docx"

   If Dir(LWordDoc) = "" Then
      MsgBox "Document not found."

   Else
      'Create an instance of MS Word
      Set oApp = CreateObject(Class:="Word.Application")
      oApp.Visible = True

      'Open the Document
      oApp.Documents.Open FileName:=LWordDoc
   End If

User avatar
HansV
Administrator
Posts: 78370
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Word Doc From Access

Post by HansV »

Insert the line

Code: Select all

        oApp.Activate
just above End If. Does that work?
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Open Word Doc From Access

Post by Leesha »

You are awesome!! That did the trick!
Thanks so much,
Leesha