locked
Send a number and date to a Word Page RRS feed

  • Question

  • I have a form that hold the information of Letters that has been sent. It assign a unique number and the current date to a form. The operator opens a word documents by pressing a button on this form. I want to show the Letter Number and the current date in the top of the Word documents that opens. The operator save the Word document and attach it to the form after saving it. How I can send the field data of the form to word documents. The code of the Command button that opens the Word document is as follow:

    Function FnWriteToWordDoc()
        Dim objWord
        Dim objDoc
        Dim objSelection
        Dim strFileName As String
       
        Set objWord = CreateObject("Word.Application")
        Set objDoc = objWord.Documents.add
        strFileName = Me.txtIndicatorNumber
       
        objWord.Visible = True
        Set objSelection = objWord.Selection
        objSelection.TypeText ("Please save the document before closing the word page")
        objDoc.SaveAs "Z:\Virsa\temp\" & strFileName
       
    End Function


    Karim Vaziri Regards,

    Saturday, April 1, 2017 6:34 PM

Answers

  • Maybe replace the TypeText line with:

    dim s as string
    s="Letter Number: " & Me.txtLetterNumber & ", Today's Date: " & Date() & vbCrLf & "Please save the document before closing the word page"
    objSelection.TypeText s

    (this assumes you have the letter number in a textbox on the form. Adjust as needed)


    -Tom. Microsoft Access MVP

    • Marked as answer by kvaziri Saturday, April 1, 2017 8:30 PM
    Saturday, April 1, 2017 6:43 PM