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

Discussion in 'Access Forms Coding' started by Ted S, Jun 30, 2013.

  1. Ted S

    Ted S Guest

    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
     
    Ted S, Jun 30, 2013
    #1
    1. Advertisements

  2. 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
    news:...

    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
     
    Douglas J Steele, Jun 30, 2013
    #2
    1. Advertisements

  3. Ted S

    Ted S Guest

    On Sunday, June 30, 2013 11:16:42 AM UTC-4, Douglas J Steele wrote:
    > 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
     
    Ted S, Jul 1, 2013
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.