f



Open a Word Doc from Access

How do i or can I open a word document directly from Access? I would like to 
be able for the user to click a button on my form to open a word document 
and then also run a macro in Word.

Thanks in advance 


0
ad_davis (40)
5/23/2005 1:48:39 PM
comp.databases.ms-access 42670 articles. 0 followers. Post Follow

3 Replies
9954 Views

Similar Articles

[PageSpeed] 19

Hi
If you are using MS Access 2003,
If you drag a button on to the form, a whizard pops up automatically,
select Applications > MS Word


best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
---------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
0
5/25/2005 4:26:05 PM
Per Andy Davis:
>How do i or can I open a word document directly from Access? I would like to 
>be able for the user to click a button on my form to open a word document 
>and then also run a macro in Word.

It will involve writing some VBA code.

This isn't exactly what you're describing, but it's probably close enough to the
the idea:
============================================================================
Private Function wordBegin(theModelName) As String
3000 debugStackPush mModuleName & ": wordBegin: "
3001 On Error GoTo wordBegin_err
     
   ' PURPOSE:  - Start an instance of MS WORD or use an existing instance
   '           - Open up a model document and saves it under a unique DOS 8.3
name
   '           - Leave a global object "gWord" pointing to the Word Basic engine
   '             behind the newly-opened document so the calling procedure can
OLE to it
   ' ACCEPTS: DOS 8.3 name of model document to be used for letter
   ' RETURNS: DOS 8.0 name of the newly-opend letter if successful, zero-length
string if failed
   '
   '   NOTES: 1) We do not want to keep opening up new instances of Word every
time this routine
   '             is called, so we do the "= Nothing" check to see if gWord has
already been set.
   '             OTHO the user may have closed that instance of Word, leaving
gWord pointing to
   '             Neverneverland.   Experimentation shows that an error 2753 is
generated in this case.
   '             Hence the error trap and the "userClosedWord" switch.
   '          2) In the FileSaveAs, it is important to force the document type
to Word.  Otherwise, if
   '             the models are Word 7 and the user is in Word 8, the document
will default to .RTF
   '             and paragraph marks will not work (.RTF needs CRLF wheras Word
used just CR)

     Dim modelPath       As String
     Dim LetterPath      As String
     Dim dosName         As String
     Dim problemPath     As String
     Dim userClosedWord  As Integer

     Const oleError = 2753

3009 modelPath = pathDatDbGet("tblPerson") & "\Models"
3010 LetterPath = pathDatDbGet("tblPerson") & "\Letters"
     
     On Error Resume Next
     MkDir LetterPath
     On Error GoTo wordBegin_err

3020 dosName = Format$(recordNumberNextGet("LetterNumber"), "00000000") & ".DOC"

wordBegin_loop:
3390  If (gWord Is Nothing) Or (userClosedWord = 1) Then
3391      Set gWord = CreateObject("Word.Application.8")
3392  End If

3395 problemPath = modelPath & "\" & theModelName
3400 gWord.ChangeFileOpenDirectory (modelPath)                 'DMN
3401 gWord.Documents.Open (theModelName)

3405 problemPath = LetterPath & "\" & theModelName
3410 gWord.ChangeFileOpenDirectory (LetterPath)                'DMN
3411 gWord.ActiveDocument.SaveAs (dosName)                     'DMN

3999 wordBegin = dosName

wordBegin_xit:
 debugStackPop
 On Error Resume Next
 Exit Function

wordBegin_err:
  Select Case Err
    Case 2763
         MsgBox "Microsoft Word is unable to find " & problemPath & ".  Please
notify your administrator", 16, "Cannot Print Form Letter"
         Resume wordBegin_xit
    Case 2772
         MsgBox "Unable to locate Microsoft Word program.  Please notify your
administrator", 16, "Cannot Print Form Letter"
         Resume wordBegin_xit
    Case oleError, mRpcServerUnavailable
         If userClosedWord = 0 Then
            userClosedWord = userClosedWord + 1
            Resume wordBegin_loop
         Else
            bugAlert "Unable to open MS Word.   Suspect user may have closed
existing instance."
            Resume wordBegin_xit
         End If
    Case Else
         bugAlert ""
         Resume wordBegin_xit
  End Select
  Resume wordBegin_xit           'Shouldn't be needed, but just in case.....
End Function
============================================================================
-- 
PeteCresswell
0
PeteCresswell
5/26/2005 2:32:28 AM
Chandra

Thanks for the advice. I've tried this bit it only opens the Word 
application. (Unless I've missed a specific step?). My users want the 
document opening in addition to launching Word as well as they don't want to 
be searching around for the file!

Might have to give Pete's code a stab if no simpler solution is available.

Many thanks again.

Dawn
"Chandra" <chandra@discussions.hotmail.com> wrote in message 
news:xG1le.43$XO4.1455@news.uswest.net...
> Hi
> If you are using MS Access 2003,
> If you drag a button on to the form, a whizard pops up automatically,
> select Applications > MS Word
>
>
> best Regards,
> Chandra
> http://groups.msn.com/SQLResource/
> http://chanduas.blogspot.com/
> ---------------------------------------
>
> *** Sent via Developersdex http://www.developersdex.com *** 


0
ad_davis (40)
5/26/2005 6:21:20 AM
Reply: