Print section of a word document from an access button click event.


T

Ted S

I'm building a database to drive a work order system. I have a set of about 30 word 2003 documents that each contains from 1 up to 6 PM tasks. I've found that I can edit the .doc's, paint the text of the individual task andassign it a bookmark name so that whenever the named bookmark is selected the text of that task is selected/painted.

I want to enable the user to print out the bookmarked task with a buttonclick such that Access opens Word, selects the bookmark, prints the selected text and quits word without saving.

This code works but it prompts to save. How can I close without saving? Many thanks in advance for your efforts and assistance.

Private Sub Command12_Click()

Dim strFile As String

Dim Wd As Object
Set Wd = CreateObject("Word.Application")
strFile = "F:\PM\08\MIP\AutoPurger.doc"
Set Wd = GetObject(strFile)
Wd.Windows(1).Visible = False

With Wd.ActiveWindow
.Selection.GoTo Name:="OperationalInspection"
.Selection.Find.ClearFormatting
.Application.PrintOut FileName:="", Range:=1
End With
Wd.Application.Quit , 0
Set Wd = Nothing
End Sub
 
Ad

Advertisements

D

Douglas J Steele

See whether closing the document and explicitly telling it not to save
helps.

You should be able to use

Wd.Documents(1).Close SaveChanges:=0


"Ted S" wrote in message

I'm building a database to drive a work order system. I have a set of about
30 word 2003 documents that each contains from 1 up to 6 PM tasks. I've
found that I can edit the .doc's, paint the text of the individual task and
assign it a bookmark name so that whenever the named bookmark is selected
the text of that task is selected/painted.

I want to enable the user to print out the bookmarked task with a button
click such that Access opens Word, selects the bookmark, prints the selected
text and quits word without saving.

This code works but it prompts to save. How can I close without saving?
Many thanks in advance for your efforts and assistance.

Private Sub Command12_Click()

Dim strFile As String

Dim Wd As Object
Set Wd = CreateObject("Word.Application")
strFile = "F:\PM\08\MIP\AutoPurger.doc"
Set Wd = GetObject(strFile)
Wd.Windows(1).Visible = False

With Wd.ActiveWindow
.Selection.GoTo Name:="OperationalInspection"
.Selection.Find.ClearFormatting
.Application.PrintOut FileName:="", Range:=1
End With
Wd.Application.Quit , 0
Set Wd = Nothing
End Sub
 
Ad

Advertisements

T

Ted S

See whether closing the document and explicitly telling it not to save
helps.

You should be able to use

Wd.Documents(1).Close SaveChanges:=0
That was close. I used Wd.Application.Quit SaveChanges:=0. It closed before the spooler could print, so a timer had to be added.
Thanks for your help

Private Sub Command12_Click()
Dim strFile As String
Dim Wd As Object
Set Wd = CreateObject("Word.Application")
strFile = "F:\PSM\08\MIP\AutoPurger.doc"
Set Wd = GetObject(strFile)
Wd.Windows(1).Visible = False

With Wd.ActiveWindow
.Selection.GoTo Name:="OperationalInspection"
.Selection.Find.ClearFormatting
.Application.PrintOut FileName:="", Range:=1
End With
For x = 1 To 10000: Next x
Wd.Application.Quit SaveChanges:=0
Set Wd = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top