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

  • Thread starter Thread starter Ted S
  • Start date Start date
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
 
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
 
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
 
Back
Top