Hello:
I am using the current code to create mailing labels in Word directly from VB..it pulls personnel data straight from the data table and creates the 5160-style mailing labels:
Sub MailMergeLabels()
Dim LabelType As String
Dim SQL1 As String
Dim oAutoText As Object
Set oApp = CreateObject("Word.Application"
SQL1 = "SELECT [First], [Last], [ADR], [CITYIN], [STATEIN], [ZIPIN] FROM Master"
Set oDoc = oApp.Documents.Add
With oDoc.MailMerge
With .Fields
.Add oApp.Selection.Range, UCase("First"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, UCase("Last"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "Adr"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "Cityin"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Statein"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Zipin"
End With
Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", oDoc.Content)
oDoc.Content.Delete
.MainDocumentType = 1:
.OpenDataSource Name:=App.Path & "\OOTSPersonnel.mdb", SQLStatement:=SQL1, ReadOnly:=True
oApp.MailingLabel.CreateNewDocument Name:="5160", Address:="", _
AutoText:="MyLabelLayout", LaserTray:=wdPrinterManualFeed
.Destination = wdSendToNewDocument
oAutoText.Delete
End With
oDoc.Close False
oApp.Visible = True
oApp.NormalTemplate.Saved = True
End Sub
***********************************************************
now I am having a hard time getting this same data (the personal address and name info) into just a standard word document. Basically I want to create a word document with todays date, the employees contact data (from the recordsource) and maybe a couple strings such as "subject", etc...I want to build a form letter.
I have tried several renditions, but I can only get these mailing labels to work...I think I am missing something, but I don't know what. Can anyone tell me another way, or a way by modifying this current code that I can create a simple form letter? Thanks
I am using the current code to create mailing labels in Word directly from VB..it pulls personnel data straight from the data table and creates the 5160-style mailing labels:
Sub MailMergeLabels()
Dim LabelType As String
Dim SQL1 As String
Dim oAutoText As Object
Set oApp = CreateObject("Word.Application"
SQL1 = "SELECT [First], [Last], [ADR], [CITYIN], [STATEIN], [ZIPIN] FROM Master"
Set oDoc = oApp.Documents.Add
With oDoc.MailMerge
With .Fields
.Add oApp.Selection.Range, UCase("First"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, UCase("Last"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "Adr"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "Cityin"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Statein"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Zipin"
End With
Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", oDoc.Content)
oDoc.Content.Delete
.MainDocumentType = 1:
.OpenDataSource Name:=App.Path & "\OOTSPersonnel.mdb", SQLStatement:=SQL1, ReadOnly:=True
oApp.MailingLabel.CreateNewDocument Name:="5160", Address:="", _
AutoText:="MyLabelLayout", LaserTray:=wdPrinterManualFeed
.Destination = wdSendToNewDocument
oAutoText.Delete
End With
oDoc.Close False
oApp.Visible = True
oApp.NormalTemplate.Saved = True
End Sub
***********************************************************
now I am having a hard time getting this same data (the personal address and name info) into just a standard word document. Basically I want to create a word document with todays date, the employees contact data (from the recordsource) and maybe a couple strings such as "subject", etc...I want to build a form letter.
I have tried several renditions, but I can only get these mailing labels to work...I think I am missing something, but I don't know what. Can anyone tell me another way, or a way by modifying this current code that I can create a simple form letter? Thanks