Access working with Microsoft Word

Mechele

Registered User.
Local time
Today, 16:57
Joined
Jan 25, 2002
Messages
121
Does anyone know the code to have access activate Microsoft Word and then have Microsoft Word open a report that wasn't generated by access?

I use the following to activate Microsoft word, but I don't know the code to tell it to open a document that wasn't generated by access....

On Error GoTo Err_Command76_Click

Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Exit_Command76_Click:
Exit Sub

Err_Command76_Click:
MsgBox Err.Description
Resume Exit_Command76_Click

:confused:
 
My favourite way of doing this to use the FollowHyperlink method.

Application.FollowHyperlink "PathToWordFile"
 
THANKS!

THANK YOU!! :)
 
One more thing

What code do I use to tell it to print automatically after it opens the document?:)
 
Ah, now that's a different 'kettle of fish', you will not be able to achieve that by using the FollowHyperlink method, you must grab the word object and manipulate it, here's some sample code to play with:

Code:
Public Function PrintLetters()
'You must put Word in the DAO Reference Library.
    Dim Dbs As Database
    Dim appWord As Word.Application
    Dim Worddoc As String
   
    Worddoc = "C:\AAA My Documents\AISolutions\Products\Y2K9 Conrol\Y2K9 Product\Letters\dog warden questionnaire - stray.dot"

    'Switch to Microsoft Word so it won't go away when you finish.
    On Error Resume Next
    AppActivate "Microsoft Word"
    
    'If Word isn't running, start and activate it
    If Err Then
    Shell "c:\Program Files\Microsoft Office\Office\" _
        & "Winword /Automation", vbMaximizedFocus
    AppActivate "Microsoft Word"
    End If
    On Error GoTo 0
    
    'Get an Application object so you can automate Word.
    Set appWord = GetObject(, "Word.Application")
    
    With appWord
        .Documents.Add Worddoc
        .ActiveDocument.PrintOut
    End With
    
Set Dbs = Nothing
Set appWord = Nothing

End Function
 
THANK YOU! THANK YOU! THANK YOU!

you're the greatest!! :O):)
 

Users who are viewing this thread

Back
Top Bottom