?
Solved

Access VBA and objWord

Posted on 2009-04-30
8
Medium Priority
?
735 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:kenabbott
  • 5
  • 2
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24273452
Well u are creating a doc, why dont you force the save yourself

along the lines of

objword.documents.save
0
 
LVL 7

Expert Comment

by:shambalad
ID: 24273480
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
 
LVL 7

Expert Comment

by:shambalad
ID: 24273492
took a few seconds too many seconds to write that post, I guess....
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 65

Expert Comment

by:rockiroads
ID: 24273522
Just double checked the exact syntax, you can use activedocument

objWord.ActiveDocument.Save

or to specify a file

objWord.ActiveDocument.SaveAs "filename"

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24273535
sorry shambalad, I didnt refresh, as I went to check syntax.
0
 

Author Comment

by:kenabbott
ID: 24273933
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24273979
ok, so when you quit, just specify false

objWord.Quit false
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 24274016
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question