Access VBA and objWord

Hi

I am using the code below to put values into a word document using bookmarks.  This works fine but when run it asks where to save the document and you can then either save it or press cancel to avoid saving.

How can I amend the code so that the document appears without the do you want to save dialogue box appearing

Many thanks
'create object and populate bookmarks
            Set objWord = CreateObject("Word.Application")
            objWord.Documents.Add strTemplate
            objWord.Visible = True
    
        With objWord.ActiveDocument.Bookmarks
            .Item("Addr").range.Text = strAddress
            .Item("ourref").range.Text = strOurRef
            .Item("yourref").range.Text = strYourRef
            
            
        End With
        
        
    End Select
    
    objWord.Quit

Open in new window

kenabbottAsked:
Who is Participating?
 
rockiroadsConnect With a Mentor Commented:
oops, above is automated close

Now ff it needs to be displayed, inspected, then printed then Im assuming some manual process involved. If its manually closed, you will always get a prompt. I dont know of any other way. Maybe better off asking in the Word forum as this seems to be a word issue not msaccess
0
 
rockiroadsCommented:
Well u are creating a doc, why dont you force the save yourself

along the lines of

objword.documents.save
0
 
shambaladCommented:
Try this:
   Dim strDOcument As String
   strDOcument = "C:mydocument.doc"
 
 'create object and populate bookmarks
            Set objWord = CreateObject("Word.Application")
            objWord.Documents.Add strTemplate
            objWord.SaveAs filename:=strDocument
            objWord.Visible = True
    
        With objWord.ActiveDocument.Bookmarks
            .Item("Addr").Range.Text = strAddress
            .Item("ourref").Range.Text = strOurRef
            .Item("yourref").Range.Text = strYourRef
            

Open in new window

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
shambaladCommented:
took a few seconds too many seconds to write that post, I guess....
0
 
rockiroadsCommented:
Just double checked the exact syntax, you can use activedocument

objWord.ActiveDocument.Save

or to specify a file

objWord.ActiveDocument.SaveAs "filename"

0
 
rockiroadsCommented:
sorry shambalad, I didnt refresh, as I went to check syntax.
0
 
kenabbottAuthor Commented:
Hi

The specific requirement is here is not to save the document - it just needs to be displayed, inspected,  printed and then closed without saving
0
 
rockiroadsCommented:
ok, so when you quit, just specify false

objWord.Quit false
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.