Auto Print Word document after populated data

stu_c

Registered User.
Local time
Today, 04:22
Joined
Sep 20, 2007
Messages
492
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 :)
 
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
 
thank you!
 

Users who are viewing this thread

Back
Top Bottom