Auto Print Word document after populated data (1 Viewer)

stu_c

Registered User.
Local time
Today, 11:17
Joined
Sep 20, 2007
Messages
489
Hi all
I have an Acess form that is filled out and when a button is clicked populates into a word document is there a way to make this process automated so it automatically prints and closes the word document (without saving)

Code:
Public Function FUNC_CreateEnvelope()

'FIND WORD FILE
    Dim oWd  As Object 'Word.Application
    Dim oDoc As Object 'Word.Document
    Dim bm   As Object 'Word.Bookmark
   
    'Set oWd = New Word.Application
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Add("C:/Word Documents\FormTemplate.docx")


'CUSTOMER ENTRY
    Set bm = oDoc.Bookmarks("C5CustomerName")
    bm.Range.Text = UCase([Forms]![FRM_TBLALL_FullDetails]![SSFRM_TBLALL_OrderDetails].[Form]![CmbCustomerNo].Column(0) & " " _
        & [Forms]![FRM_TBLALL_FullDetails]![SSFRM_TBLALL_OrderDetails].[Form]![CmbCustomerName].Column(2) & "")
    oWd.Visible = True

End Function

Obviously there is more details thats just the basics :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:17
Joined
May 7, 2009
Messages
19,169
you can issue the PrintOut command:
Code:
Public Function FUNC_CreateEnvelope()

'FIND WORD FILE
    Dim oWd  As Object 'Word.Application
    Dim oDoc As Object 'Word.Document
    Dim bm   As Object 'Word.Bookmark
  
    'Set oWd = New Word.Application
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Add("C:/Word Documents\FormTemplate.docx")


'CUSTOMER ENTRY
    Set bm = oDoc.Bookmarks("C5CustomerName")
    bm.Range.Text = UCase([Forms]![FRM_TBLALL_FullDetails]![SSFRM_TBLALL_OrderDetails].[Form]![CmbCustomerNo].Column(0) & " " _
        & [Forms]![FRM_TBLALL_FullDetails]![SSFRM_TBLALL_OrderDetails].[Form]![CmbCustomerName].Column(2) & "")
    oDoc.PrintOut

    'Close but dont save
    oDoc.Close False

    Set oDoc = Nothing
    Set oWd = Nothing
    'oWd.Visible = True

End Function
 

stu_c

Registered User.
Local time
Today, 11:17
Joined
Sep 20, 2007
Messages
489
thank you!
 

Users who are viewing this thread

Top Bottom