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

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.
Similar Threads
  1. cmb

    Event to trap navigation button click?

    cmb, Aug 21, 2003, in forum: Access Forms Coding
    Replies:
    3
    Views:
    146
  2. Kunjal Karamshi

    Access 2002 Command button Click event reentrant in nature?

    Kunjal Karamshi, Dec 1, 2003, in forum: Access Forms Coding
    Replies:
    2
    Views:
    284
  3. Mike Elliott
    Replies:
    4
    Views:
    237
    Dirk Goldgar
    Oct 20, 2004
  4. reservedbcreater

    beforeupdate event and button click event collision

    reservedbcreater, Feb 9, 2005, in forum: Access Forms Coding
    Replies:
    0
    Views:
    177
    reservedbcreater
    Feb 9, 2005
  5. charlie via AccessMonster.com

    click on subform, then click on button to open form to rcd in subform

    charlie via AccessMonster.com, Aug 8, 2006, in forum: Access Forms Coding
    Replies:
    0
    Views:
    157
    charlie via AccessMonster.com
    Aug 8, 2006
  6. TonyT

    Click or Double Click Event

    TonyT, Oct 21, 2006, in forum: Access Forms Coding
    Replies:
    1
    Views:
    164
  7. trevorC via AccessMonster.com

    return to first button click event after another button click event

    trevorC via AccessMonster.com, Dec 4, 2009, in forum: Access Forms Coding
    Replies:
    1
    Views:
    236
    John W. Vinson
    Dec 4, 2009
  8. jlg via AccessMonster.com

    Click Image and call label Click event

    jlg via AccessMonster.com, May 11, 2010, in forum: Access Forms Coding
    Replies:
    0
    Views:
    138
    jlg via AccessMonster.com
    May 11, 2010
Loading...