Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Form to MS Word form

Status
Not open for further replies.

bettaa

IS-IT--Management
Feb 28, 2006
20
US
My company is currently using a MS Access 2003 database. I have several fields that i commonly copy and paste information from the database and insert into a fax cover sheet. I was wondering how i could pass information from the current Access entry to Word, so I could save time, and increase accuracy.

thanks in advance!

--bettaa
 
The following code will create a Fax Cover Sheet in Word. You will of course need to add a reference to Microsoft Word Object Model.

Code:
Private Sub btnRun_Click()

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim myTable As Word.Table
Dim para As Word.Paragraph

    Set objWord = New Word.Application
    objWord.Documents.Add
    Set objDoc = objWord.ActiveDocument

    objDoc.Windows(1).Selection.Font.Name = "Arial"

    With objDoc.Windows(1).Selection
        
        Set para = .Range.Paragraphs.Add
        With para
            .Range.Font.Size = 32
            .Range.Text = "FAX"
            .Range.HighlightColorIndex = wdBlack
            .Range.Font.Color = wdColorWhite
        End With
        .EndKey (wdStory)
        .Range.Paragraphs.Add
        .Range.Paragraphs.Add
        .EndKey (wdStory)
        Set myTable = .Tables.Add(.Range, 3, 4)
        With myTable
            .Range.HighlightColorIndex = wdAuto
            .Range.Font.Color = wdColorBlack
            .Range.Font.Size = 8
            
            .Cell(1, 1).Range.Text = "TO:"
            .Cell(1, 2).Range.Text = "<<Recipient's Name>>"
            .Cell(1, 3).Range.Text = "FROM:"
            .Cell(1, 4).Range.Text = "<<Your Name>>"
            .Cell(2, 1).Range.Text = "FAX:"
            .Cell(2, 2).Range.Text = "<<Recipient's  Fax>>"
            .Cell(2, 3).Range.Text = "PAGES:"
            .Cell(2, 4).Range.Text = ""
            .Cell(3, 1).Range.Text = "SUBJECT:"
            .Cell(3, 2).Range.Text = "<<This is a Test>>"
            .Cell(3, 3).Range.Text = "DATE:"
            .Cell(3, 4).Range.Text = "<<1/1/2007>>"
        End With
    End With
    
objWord.Visible = True


Set myTable = Nothing
Set rng = Nothing
Set objDoc = Nothing
Set objWord = Nothing

End Sub
 
So, i have a template that I already use, how could I send the information to specific areas within the word document?
 
Would need more details on how you set/plan to use "specific areas" - are these bookmarks? formfields? - but sure.

With the Word instance instead of making a new blank document, make a new document with your template, then simply put the information into the "specific areas".

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top