Solved

Posted on 2011-09-23
799 Views
And the word document , when saved to the lan, I am not able to open the document.
WORD DOCUMENT DOUBLE SPACES
On Tuesday I put desk top icons on the desks of Lori Kerns and Lori Lindgren to access the merge program from a single network location.
On the computer of Lori Kerns, the Word Merge worked perfectly.
On the computer of Lori Lindgren, everyplace I have a carriage return line feed or  vb .net command to format a new paragraph,
the  Word Document  Double Spaces.

Research and discussion suggested this to be a WORD TEMPLATE issue.
I found and renamed my WORD TEMPLATES and now on my machine, I am getting double spaces.
Renaming my WORD TEMPLATES back does not solve my problem.
SO NOW, might have to, in the program, merge the fields.  WILL TRY THIS.

AND now on the V drive and some U drive folders, CAN NOT OPEN THE WORD DOCUMENT.
Error Message indicate this might be permissions or the word document is corrupt.
RESEARCHING.

My Input file:
Input file,   v:\shardata\fileformailmerge.txt

"9/21/2011@@9@21@2011@9@21@2011@9@21@2011@21@11@BONNER, MARY L@626 MAGNOLIA ROAD@LAUREL                      MS 394437738@@@@LAUREL@MS@394437738@           $405.75 @26.5@xxx-xx-1671 @250300@000-00-1671@250300@000-00-1671@ 71.916667" My code: Imports Microsoft.Office.Interop.Word Imports System.Configuration Imports System.IO 'Imports System.Configuration.ConfigurationManager 'Imports System.Configuration.ConfigurationErrorsException'Dim wdExtend As Object = Microsoft.Office.Interop.Word.WdUnits.wdExtend Imports System.Collections.Specialized Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.Access Imports Microsoft.Vbe.Interop 'Imports Microsoft.Vbe.Interop.Forms.dll 'Imports Microsoft.Office.Interop.Word 'Acrobat Reader parameters Imports System.Net Imports System.Net.Sockets 'Imports Microsoft.WindowsMediaServices.Interop Imports System.Runtime.InteropServices Module Module1 Dim pExportFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF Dim sExportFilePath As String = "" Dim paramOpenAfterExport As Boolean = False Dim paramExportOptimizeFor As WdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint Dim paramExportRange As WdExportRange = WdExportRange.wdExportAllDocument Dim paramStartPage As Int32 = 2 Dim paramEndPage As Int32 = 2 Dim paramExportItem As WdExportItem = WdExportItem.wdExportDocumentContent Dim paramIncludeDocProps As Boolean = True Dim paramKeepIRM As Boolean = True Dim paramCreateBookmarks As WdExportCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks Dim paramDocStructureTags As Boolean = True Dim paramBitmapMissingFonts As Boolean = True Dim paramUseISO19005_1 As Boolean = False Dim wdline As Object = Microsoft.Office.Interop.Word.WdUnits.wdLine Dim wdCharacter As Object = Microsoft.Office.Interop.Word.WdUnits.wdCharacter ' Dim wdFieldFormCheckBox As Object = Microsoft.Office.Interop.Word.wdFieldFormCheckBox Dim sAttrX As String 'for appconfig Dim addr_length As Integer Dim lname_length As Integer Dim fname_length As Integer Dim currentField1 As String 'date Dim currentField2 As String 'blank Dim currentField3 As String 'month Dim currentField4 As String 'day Dim currentField5 As String 'year Dim currentField6 As String 'month Dim currentField7 As String 'day Dim currentField8 As String 'year Dim currentField9 As String 'month Dim currentField10 As String 'day Dim currentField11 As String 'year Dim currentField12 As String 'day Dim currentField13 As String 'year Dim currentField14 As String 'lname 'addr_length = Trim(currentField16.Length) Dim currentField15 As String 'fname 'fname_length = (Trim(currentField15.Length)) Dim currentField16 As String 'addr1 Dim currentField17 As String 'addr2 Dim currentField18 As String 'addr3 Dim currentField19 As String 'addr4 Dim currentField20 As String 'addr5 Dim currentField21 As String 'city Dim currentField22 As String 'state Dim currentField23 As String 'zip Dim currentField24 As String 'rmd1000 Dim currentField24a As String ' comman for 1000 rmd amount Dim currentField25 As String 'rmdamount Dim currentField26 As String 'rmd factor Dim currentField27 As String 'ssn Dim currentField28 As String 'plan no Dim currentField29 As String 'namefirst Dim currentField30 As String 'namelast Dim currentField31 As String 'addr1 Dim currentField32 As String 'addr2 Dim currentField33 As String 'addr3 Dim currentField34 As String 'addr4 Dim currentField35 As String 'addr5 Dim currentField36 As String 'city Dim currentField37 As String 'state Dim currentField38 As String 'zip Dim currentField39 As String 'ssn work area Dim currentField40 As String ' participant age Dim currentField41 As String ' ?plan no Dim args As String() Dim oDoc As Document = Nothing Dim thisDocName As String 'Font.Name = "Arial Unicode MS" Dim oWord As Word.Application Dim whichField As Integer Dim xxxxx As ArrayList 'Dim Server As IObserver 'Dim Plugin As IWMSPlugin 'Dim IPAdmin As IWMSPlugin 'Dim IPList As IWMSPlugin 'Dim IPEntry As IWMSIPEntry 'Dim strIPAddress As String Sub Main() Dim index As Integer = 0 ' Dim buffer_icmpPacket() As Byte ' Dim cksumBuffer() As UInt16 Dim icmpHeaderBufferIndex As Int32 = 0 'type_message = Type ' Me.type_message = Type 'Me.subCode_type = subCode 'complement_checkSum = UInt16.Parse("0") 'identifier = UInt16.Parse("45") 'sequenceNumber = UInt16.Parse("0") 'Data = payload ' Dim IPAddress As IPAddress = Dns.GetHostEntry(Dns.GetHostName).AddressList(0) ' Dim strIPAddress As String = IPAddress.ToString 'For Each ip As Net.IPAddress In _ 'System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList ' ' Eg: Display with message box ' MsgBox(ip.ToString) 'Next 'Dim textboxip As String = "" 'Dim hostname As IPHostEntry = Dns.GetHostEntry(textboxip) 'Dim ip As IPAddress() = hostname.AddressList 'textboxip = ip(0).ToString() 'Dim address As String 'address = winsock1.LocalIP ' Dim IP As IPHostEntry = New IPHostEntry 'get the IP addresses associated with the host ' IP = Dns.Resolve(Dns.GetHostName) ' IP = Dns.GetHostEntry(Dns.GetHostName) ' Dim arrIP() As IPAddress = IP.AddressList ' arrIP(0).ToString() ' Dim NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); 'Dim IP As IPHostEntry = New IPHostEntry 'IP = Dns.GetHostEntry(Dns.GetHostName) 'Dim arrIP() As IPAddress = IP.AddressList 'arrIP(0).ToString() '' IP = Dns.Resolve(Dns.GetHostName) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'It sounds like the .config file is broken at some level (most likely local user or roaming user). 'To locate the files, you can add the following to the constructor of your settings class (or in the settings property get:er that you modified to always return false). 'Dim exeConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None) 'Debug.WriteLine(exeConfig.Locations) 'Debug.WriteLine(exeConfig.FilePath) 'Dim localConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal) 'Debug.WriteLine(localConfig.FilePath) 'Dim roamingConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoaming) 'Debug.WriteLine(roamingConfig.FilePath) ' load_appconfig() 'Dim sAttr As String ''sAttr = System.Configuration!System.Configuration.ConfigurationManager.AppSettings("Key0") 'sAttr = System.Configuration.ConfigurationManager.AppSettings("Spouse10Year") '' sAttr = ConfigurationSettings.AppSettings("Key0") 'Console.WriteLine("The value of Key0: " & sAttr) 'Dim sAll As NameValueCollection '' sAll = ConfigurationSettings.AppSettings() 'sAll = System.Configuration.ConfigurationManager.AppSettings() '' System.Configuration.ConfigurationManager.AppSettings 'Dim s As String 'For Each s In sAll.AllKeys ' ' Console.WriteLine("Key: " & s & " Value: " & sAll(s)) 'Next '' Console.ReadLine() ' Dim sAttr As String 'for appconfig Dim hoursDate As String Dim minsDate As String Dim secondsDate As String Dim dayDate As String Dim testDate As DateTime = Now hoursDate = Hour(testDate) minsDate = Minute(testDate) secondsDate = Second(testDate) dayDate = Day(testDate) dayDate = Date.Now.Day.ToString() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' read_file(dayDate, hoursDate, minsDate, secondsDate) Dim sDocPath As String = "" Dim wrdSelection As Word.Selection wrdSelection = Nothing Dim StrToAdd As String StrToAdd = Nothing oWord = CreateObject("Word.Application") oWord.Visible = True oDoc = oWord.Documents.Add oDoc.Select() wrdSelection = oWord.Selection ' Dim xxxxx = New ArrayList ' load_appconfig() wrdSelection.PageSetup.LeftMargin = 92.925 wrdSelection.Font.Name = "Courier" wrdSelection.Font.Size = "9.0" ' wrdSelection.Style = "No Spacing" CreateMailMergeDataFile(dayDate, hoursDate, minsDate, secondsDate) ''''''''''''''''''''' ' Insert merge data. '''''''''''''''''''''''''''''''''''''''''''' wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft wrdSelection.ParagraphFormat.Alignment = Word.WdWrapType.wdWrapInline '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft Dim myImage As String 'myImage = "C:\data\nreca_logo_4.png" myImage = CurDir() & "\nreca_logo_4.png" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.InlineShapes.AddPicture(myImage) Dim xxDateString As String 'used for month, the number Dim xxxxDateString As String 'used for year, ie 2011 Dim xxxxxDateString As String 'used for date, ie September 13, 2011 Dim xxxxxxDateString As String 'used for month spelled out xxxxxxDateString = "" xxDateString = Now.Month xxxxDateString = CStr(CStr(Now.Year)) If xxDateString = 1 Then xxxxxxDateString = "January" End If If xxDateString = 2 Then xxxxxxDateString = "February" End If If xxDateString = 3 Then xxxxxxDateString = "March" End If If xxDateString = 4 Then xxxxxxDateString = "April" End If If xxDateString = 5 Then xxxxxxDateString = "May" End If If xxDateString = 6 Then xxxxxxDateString = "June" End If If xxDateString = 7 Then xxxxxxDateString = "July" End If If xxDateString = 8 Then xxxxxxDateString = "August" End If If xxDateString = 9 Then xxxxxxDateString = "September" End If If xxDateString = 10 Then xxxxxxDateString = "October" End If If xxDateString = 11 Then xxxxxxDateString = "November" End If If xxDateString = 12 Then xxxxxxDateString = "December" End If xxxxxDateString = xxxxxxDateString + " " + CStr(Now.Day) + ", " + xxxxDateString 'used for date, ie September 13, 2011 Dim xDateLength As Integer xDateLength = xxxxxDateString.Length() Dim iii, iiii As Integer iiii = 62 - xDateLength For iii = 1 To iiii wrdSelection.TypeText(" ") Next iii wrdSelection.InsertDateTime(DateTimeFormat:="MMMM dd, yyyy", InsertAsField:=False) 'wrdSelection.TypeText("^p") wrdSelection.TypeText(Text:=vbCrLf) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(currentField15) 'first name wrdSelection.TypeText(" ") wrdSelection.TypeText(currentField14) 'last name wrdSelection.TypeText(" ") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' iii = 0 iiii = 77 - fname_length - lname_length For iii = 1 To iiii wrdSelection.TypeText(" ") Next iii ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText("SSN: ") wrdSelection.TypeText(currentField27) 'xxx-xx-xssn wrdSelection.TypeText(" ") wrdSelection.TypeParagraph() wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(currentField16) 'addr1 wrdSelection.TypeText(" ") iii = 0 For iii = 1 To (81 - addr_length) wrdSelection.TypeText(" ") Next iii ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText("REA #: ") wrdSelection.TypeText(currentField28) 'REA or Plan No wrdSelection.TypeText(" ") wrdSelection.TypeParagraph() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(currentField17) 'addr2 InsertLines(2) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify wrdSelection.TypeText("Re: Required Minimum Distribution ") InsertLines(2) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify wrdSelection.TypeText("Dear ") wrdSelection.TypeText(" ") wrdSelection.TypeText(currentField15) 'first name wrdSelection.TypeText(" ") wrdSelection.TypeText(currentField14) 'last name wrdSelection.TypeText(": ") wrdSelection.TypeText(" ") InsertLines(2) StrToAdd = "The assets in your retirement plans cannot remain tax-deferred indefinitely. Once you reach age 70½ and retire from service, the IRS requires you to withdraw at least a minimum each year. You must take an amount known as a required minimum distribution (RMD) from all of your retirement plans except Roth IRAs. " wrdSelection.TypeText(StrToAdd) InsertLines(2) StrToAdd = "Each year, NRECA will calculate your RMD for the 401(k) Pension Plan. The RMD for a year must be withdrawn by December 31st of that year, either in a lump sum or in installments. However, if you are taking an RMD for the first time, you may delay withdrawing the RMD until April 1st of the year after you turn age 70½ (or, in some cases, after you retire). If you delay taking it until the next year, you will have to take two minimum distributions during that calendar year. This can put you in a higher tax bracket for the year, increasing the tax you owe. " wrdSelection.TypeText(StrToAdd) InsertLines(2) StrToAdd = "Since you have attained the age of 70½ this year, an RMD from your 401(k) Pension Plan account will be processed. The amount of your Required Minimum Distribution is: " wrdSelection.TypeText(StrToAdd) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(currentField24) currentField25 = Trim(currentField25) wrdSelection.TypeText(currentField25) 'rmd amount '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(".") wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = " You have the option of delaying this distribution until April 1st of next year, or you can take it this year. Please indicate below your preference regarding the RMD by checking one of the boxes below: " wrdSelection.TypeText(StrToAdd) InsertLines(1) ' InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = " _ _ " wrdSelection.TypeText(StrToAdd) InsertLines(1) StrToAdd = " |_| Delay until April 1st of next Year " wrdSelection.TypeText(StrToAdd) StrToAdd = " |_| Take RMD this year " wrdSelection.TypeText(StrToAdd) ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' Dim originalFont As String = oWord.wrdSelection.Font.Name 'wrdSelection.Font.Name = "Wingdings" 'wrdSelection.Font.Size = "18.0" 'wrdSelection.Font.Bold = False '' wrdSelection.InsertAfter("p") 'StrToAdd = " " 'wrdSelection.TypeText(StrToAdd) 'StrToAdd = "p" 'wrdSelection.TypeText(StrToAdd) 'wrdSelection.Font.Name = "Wingdings" '' Dim unit As Object = Word.WdUnits.wdCharacter '' Dim count As Object = 1 '' object count = 1; '' Dim extend As Object = oWord.wdmovementType.wdMove '' object extend = Word.WdMovementType.wdMove; '' oWord.wrdSelection.MoveRight(ref unit, ref count, ref extend) '' oWord.wrdSelection.MoveRight(1, 1, 1) '' oWord.wrdSelection.Font.Name = originalFont 'wrdSelection.Font.Name = "Courier" 'wrdSelection.Font.Size = "9.0" 'StrToAdd = " Delay until April 1st of next Year " 'wrdSelection.TypeText(StrToAdd) 'wrdSelection.Font.Name = "Wingdings" 'wrdSelection.Font.Size = "18.0" 'StrToAdd = "p" 'wrdSelection.TypeText(StrToAdd) 'wrdSelection.Font.Name = "Courier" 'wrdSelection.Font.Size = "9.0" 'StrToAdd = " Take RMD this year" 'wrdSelection.TypeText(StrToAdd) ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'this.Application.Selection.InsertAfter("p"); 'this.Application.Selection.Font.Name = "Wingdings"; 'object unit = Word.WdUnits.wdCharacter; 'object count = 1; 'object extend = Word.WdMovementType.wdMove; 'this.Application.Selection.MoveRight(ref unit, ref count, ref extend); 'this.Application.Selection.Font.Name = originalFont; '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' wrdSelection.FormFields.Add(Range:=Selection.Range, Type:=Microsoft.Office.Interop.Word.CheckBox) ' Microsoft.Vbe.Interop.VBComponent() 'Microsoft.Vbe.Interop.Forms.CheckBox cx = of.Object as Microsoft.Vbe.Interop.Forms.CheckBox; 'Microsoft.Vbe.Interop.Forms.CheckBox cx = of.Object as Microsoft.Vbe.Interop.Forms.CheckBox; 'wrdSelection.FormFields.Add(Range:=Selection.Range, Type:=System.wdFieldFormCheckBox) ' oDoc.FormFields. = Range.FormFields.Add(Range, Word.WdFieldType.wdFieldFormCheckBox) ' Dim ff As oWord.FormField = Range.FormFields.Add(Range, Word.WdFieldType.wdFieldFormCheckBox) ' Dim xxxx As oWord.formfield 'Dim fff As oDoc.formfield = Range.FormFields.Add(Range, Word.WdFieldType.wdFieldFormCheckBox) ''''''''''''''''''Word.WdFieldType.wdFieldFormCheckBox 'oDoc.wrdSelection.FormFields.Add(Range:=Selection.Range, Type:=Word.WdFieldType.wdFieldFormCheckBox) 'this.Paragraphs[1].Range.InsertParagraphBefore() 'Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark(this.Paragraphs[1].Range,"bookmark1") 'bookmark1.FormFields.Add(bookmark1.Range, Word.WdFieldType.wdFieldFormCheckBox) 'Dim classType As Object = "Forms.CheckBox.1" 'Dim checkBoxInlineShape as Word.InlineShape = range.InlineShapes.AddOLEControl(ref classType, ref missing); 'oWord.FormField ff = wrdSelection.range.FormFields.Add(range, Word.WdFieldType.wdFieldFormCheckBox); 'Dim Range As Microsoft.Office.Interop.Word.Range = AcControlType 'Dim ff As FormField = wrdSelection.Range.FormFields.Add(Range, Word.WdFieldType.wdFieldFormCheckBox) 'Word.FormField ff = range.FormFields.Add(range, Word.WdFieldType.wdFieldFormCheckBox); 'With ActiveDocument.FormFields.Add(Range:=ActiveDocument.Range _ ' (Start:=0, End:=0), Type:=wdFieldFormCheckBox) ' .Name = "Color" ' .CheckBox.Value = True 'End With 'With oDoc.FormFields.Add(Range:=oDoc.Range _ ' (Start:=0, End:=0), Type:=wdFieldFormCheckBox) ' .Name = "Color" ' .CheckBox.Value = True 'End With ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Dim aTable As Word.Table 'aTable = oDoc.Tables.Add(oWord.Selection.Range, 2, 5) 'aTable.Style = "Table Grid " 'aTable.Columns.Item(1).SetWidth(12, Word.WdRulerStyle.wdAdjustNone) 'aTable.Columns.Item(2).SetWidth(44, Word.WdRulerStyle.wdAdjustNone) 'aTable.Columns.Item(3).SetWidth(210, Word.WdRulerStyle.wdAdjustNone) 'aTable.Columns.Item(4).SetWidth(29, Word.WdRulerStyle.wdAdjustNone) 'aTable.Columns.Item(5).SetWidth(164, Word.WdRulerStyle.wdAdjustNone) 'Dim x1 As Char 'x1 = "" 'aTable.Cell(1, 1).Range.Text = x1 'aTable.Cell(1, 2).Range.Text = " _ " 'aTable.Cell(1, 3).Range.Text = x1 'aTable.Cell(1, 4).Range.Text = " _ " 'aTable.Cell(1, 5).Range.Text = x1 'aTable.Cell(2, 1).Range.Text = x1 'aTable.Cell(2, 2).Range.Text = "|_|" 'aTable.Cell(2, 3).Range.Text = "Delay until April 1st of next Year" 'aTable.Cell(2, 4).Range.Text = "|_|" 'aTable.Cell(2, 5).Range.Text = "Take RMD this year" 'With oWord.Selection ' .SetRange(aTable.Range.End + 1, aTable.Range.End + 1) ' .Collapse(Word.WdCollapseDirection.wdCollapseEnd) 'End With ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'With wrdSelection.Tables(1) ' .AutoFormat( _ ' Format:=WdTableFormat.wdTableFormat3DEffects1, _ ' ApplyBorders:=True, _ ' ApplyShading:=False, _ ' ApplyFont:=True, _ ' ApplyColor:=True, _ ' ApplyHeadingRows:=True, _ ' ApplyLastRow:=True, _ ' ApplyFirstColumn:=True, _ ' ApplyLastColumn:=True, _ ' AutoFit:=False) 'End With 'InsertLines(1) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(1) InsertLines(1) StrToAdd = "Note: If you do not return this letter with your selection, we will delay this RMD until April 1st of next year. " wrdSelection.TypeText(StrToAdd) InsertLines(2) StrToAdd = "Regardless if you elect to defer this payment or not, 10% federal withholding will be applied to your required minimum distribution unless you check the box below. " wrdSelection.TypeText(StrToAdd) InsertLines(1) ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = " _ " wrdSelection.TypeText(StrToAdd) InsertLines(1) StrToAdd = " |_| I elect not to have federal income tax withheld " wrdSelection.TypeText(StrToAdd) ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'wrdSelection.Font.Name = "Wingdings" 'wrdSelection.Font.Size = "18.0" 'StrToAdd = " p" 'wrdSelection.TypeText(StrToAdd) 'wrdSelection.Font.Name = "Courier" 'wrdSelection.Font.Size = "9.0" 'StrToAdd = " I elect not to have federal income tax withheld " 'wrdSelection.TypeText(StrToAdd) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(2) StrToAdd = "Please complete the information below if you wish to receive your payment by direct deposit regardless if you defer your payment or not. You must attach a voided check as verification of your bank information. " wrdSelection.TypeText(StrToAdd) InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(1) Dim bTable As Word.Table bTable = oDoc.Tables.Add(oWord.Selection.Range, 2, 3) bTable.Style = "Table Grid" bTable.Columns.Item(1).SetWidth(125, Word.WdRulerStyle.wdAdjustNone) bTable.Columns.Item(2).SetWidth(131, Word.WdRulerStyle.wdAdjustNone) bTable.Columns.Item(3).SetWidth(269, Word.WdRulerStyle.wdAdjustNone) bTable.Cell(2, 1).Height = 30 bTable.Cell(2, 2).Height = 30 bTable.Cell(2, 3).Height = 30 bTable.Cell(1, 1).Range.Text = "Bank Routing Number" bTable.Cell(1, 2).Range.Text = "Bank Account Number" bTable.Cell(1, 3).Range.Text = "Name of your Financial Institution" With oWord.Selection .SetRange(bTable.Range.End + 1, bTable.Range.End + 1) .Collapse(Word.WdCollapseDirection.wdCollapseEnd) End With InsertLines(0) InsertLines(1) Dim cTable As Word.Table cTable = oDoc.Tables.Add(oWord.Selection.Range, 2, 4) cTable.Style = "Table Grid" cTable.Columns.Item(1).SetWidth(277, Word.WdRulerStyle.wdAdjustNone) cTable.Columns.Item(2).SetWidth(82, Word.WdRulerStyle.wdAdjustNone) cTable.Columns.Item(3).SetWidth(82, Word.WdRulerStyle.wdAdjustNone) cTable.Columns.Item(4).SetWidth(84, Word.WdRulerStyle.wdAdjustNone) cTable.Cell(2, 1).Height = 30 cTable.Cell(2, 2).Height = 30 cTable.Cell(2, 3).Height = 30 cTable.Cell(2, 4).Height = 30 cTable.Cell(1, 1).Range.Text = "Mailing Address of the Financial Institution" cTable.Cell(1, 2).Range.Text = "City" cTable.Cell(1, 3).Range.Text = "State" cTable.Cell(1, 4).Range.Text = "Zip" With oWord.Selection .SetRange(cTable.Range.End + 1, cTable.Range.End + 1) .Collapse(Word.WdCollapseDirection.wdCollapseEnd) End With InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = "Please consult your personal tax advisor to determine which option is right for you. Once you have reached a decision, you should sign this letter and return it to: NRECA RPD Unit, PO Box 6127, Lincoln, NE 68506." wrdSelection.TypeText(StrToAdd) InsertLines(3) StrToAdd = "____________________________________________________ ______________" wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft wrdSelection.TypeText(StrToAdd) InsertLines(1) StrToAdd = "Name (signature required) Date " wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft wrdSelection.TypeText(StrToAdd) InsertLines(1) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft InsertLines(1) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft StrToAdd = "Please feel free to contact the Member Contact Center at 866.673.2299 or contactcenter@nreca.coop and ask to be transferred to the 401(k) Pension Plan Unit. " wrdSelection.TypeText(StrToAdd) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(8) StrToAdd = " P.O. Box 6127 - Lincoln, NE 68506 - tel: 866.673.2299 - www.nreca.coop " wrdSelection.TypeText(StrToAdd) InsertLines(1) 'Dim wdPasteDefault As String = " P.O. Box 6127 - Lincoln, NE 68506 - tel: 866.673.2299 - www.nreca.coop " 'oDoc.ViewFooterOnly() 'oWord.viewfooteronly() '' WordBasic.ViewFooterOnly() ''ActiveDocument.AttachedTemplate.BuildingBlockEntries(" Blank").Insert( _ '' Where:=Selection.Range, RichText:=True) 'wrdSelection.PasteAndFormat(wdPasteDefault) 'wrdSelection.Delete(Unit:=wdCharacter, Count:=1) 'wrdSelection.Delete(Unit:=wdCharacter, Count:=1) 'wrdSelection.Delete(Unit:=wdCharacter, Count:=1) 'wrdSelection.HomeKey(Unit:=wdline) 'wrdSelection.TypeText(Text:=" ") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.Font.Name = "Courier" wrdSelection.Font.Size = "14.0" wrdSelection.Font.Size = "12.0" wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft InsertLines(1) oWord.InchesToPoints(0.02) oWord.MillimetersToPoints(4) InsertLines(6) InsertLines(3) StrToAdd = " " wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(currentField30) 'first name wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(" ") StrToAdd = Trim(currentField29) wrdSelection.TypeText(StrToAdd) 'last name wrdSelection.TypeText(Text:=vbCrLf) 'wrdSelection.TypeText(Text:="^p") StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(currentField31) 'addr1 wrdSelection.TypeText(StrToAdd) 'wrdSelection.TypeText("^p") wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(currentField32) 'addr2 wrdSelection.TypeText(StrToAdd) 'wrdSelection.TypeText("^p") wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(currentField33) 'addr3 wrdSelection.TypeText(StrToAdd) 'wrdSelection.TypeText("^p") wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(currentField34) 'addr4 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) 'wrdSelection.TypeText("^p") StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(currentField35) 'addr5 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) 'wrdSelection.TypeText("^p") InsertLines(1) 'StrToAdd = "- - - - - - - - - - - - - - - - - - - - - - " StrToAdd = "- - - - - " wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) 'wrdSelection.TypeText("^p") Dim xmargin = wrdSelection.PageSetup.LeftMargin ' 92.95 Dim ymargin = wrdSelection.PageSetup.RightMargin ' 90.00 Dim tmargin = wrdSelection.PageSetup.TopMargin ' 72.00 Dim bmargin = wrdSelection.PageSetup.BottomMargin ' 72.00 wrdSelection.PageSetup.LeftMargin = 55.0 wrdSelection.PageSetup.RightMargin = 40.0 wrdSelection.PageSetup.TopMargin = 27.0 'wrdSelection.PageSetup.BottomMargin = 50.0 'wrdSelection.PageSetup.BottomMargin = 4.0 'wrdSelection.PageSetup.BottomMargin = 32.0 wrdSelection.PageSetup.BottomMargin = 2.0 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim docName As String ' docName = "U:\Backup_RMD_Files\RMD_merge_" + ' Trim(currentField27) + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + minsDate + "_" + secondsDate + "." + "doc" docName = "V:\Shardata\Backup_RMD_Files\RMD_merge_" + Trim(currentField27) + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + minsDate + "_" + secondsDate + "." + "doc" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' If dao.Document.ProtectionType = WdProtectionType Then _ ' dao.Document.Protect(Password:="ABCD", NoReset:=True, Type:=wdAllowOnlyFormFields) ' Err.Clear() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' myDoc = Documents("Monthly Report.doc") ' myDoc.Protect(Type:=wdAllowOnlyComments, Password:="free") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' With oDoc paramOpenAfterExport = False Dim und_score As String und_score = "_" pExportFormat = WdExportFormat.wdExportFormatXPS 'sExportFilePath = "U:\Doc\RMD_doc_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc" sExportFilePath = "V:\Shardata\Doc\RMD_doc_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc" oDoc.ExportAsFixedFormat(sExportFilePath, _ pExportFormat, paramOpenAfterExport, _ paramExportOptimizeFor, paramExportRange, paramStartPage, _ paramEndPage, paramExportItem, paramIncludeDocProps, _ paramKeepIRM, paramCreateBookmarks, _ paramDocStructureTags, paramBitmapMissingFonts, _ paramUseISO19005_1) oDoc.SaveAs(docName) 'myDoc = Documents(docName) 'myDoc.Protect(Type:=wdAllowOnlyComments, Password:="free") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim myMailMergeDoc As Document = oWord.Documents.Open(docName) myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName) myMailMergeDoc.MailMerge.Application.ActiveDocument.BuiltInDocumentProperties.ToString() 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdNoProtection) 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyRevisions) 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyReading) 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyComments) 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdNoProtection, NoReset:=vbNo, Password:="a12345") 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyRevisions, NoReset:=vbNo, Password:="b456") 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyReading, NoReset:=vbNo, Password:="c567") 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyComments, NoReset:=vbNo, Password:="d678") ' wrdSelection.Delete(Unit:=oWord.Documents.Count()) 'wrdSelection.Delete(Unit:=oWord.Documents.Count()) 'wrdSelection.Delete(Unit:=oWord.Documents.Count()) End With With oDoc paramOpenAfterExport = False Dim und_score As String und_score = "_" pExportFormat = WdExportFormat.wdExportFormatXPS 'sExportFilePath = "U:\Doc\RMD_doc_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc" sExportFilePath = "V:\RPD\401k Payments\RMD\RMD Auto Letters\_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".docmx" oDoc.ExportAsFixedFormat(sExportFilePath, _ pExportFormat, paramOpenAfterExport, _ paramExportOptimizeFor, paramExportRange, paramStartPage, _ paramEndPage, paramExportItem, paramIncludeDocProps, _ paramKeepIRM, paramCreateBookmarks, _ paramDocStructureTags, paramBitmapMissingFonts, _ paramUseISO19005_1) oDoc.SaveAs(docName) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim myMailMergeDoc As Document = oWord.Documents.Open(docName) myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName) myMailMergeDoc.MailMerge.Application.ActiveDocument.BuiltInDocumentProperties.ToString() Dim xxx As String = myMailMergeDoc.MailMerge.Application.ActiveDocument.ProtectionType ' = WdProtectionType.wdNoProtection 'myMailMergeDoc.MailMerge.Application.ActiveDocument.Protect(WdProtectionType.wdNoProtection) Dim xxxxx As String = myMailMergeDoc.MailMerge.Application.ActiveDocument.ProtectionType ' = WdProtectionType.wdNoProtection ' wrdSelection.Delete(Unit:=oWord.Documents.Count()) 'wrdSelection.Delete(Unit:=oWord.Documents.Count()) 'wrdSelection.Delete(Unit:=oWord.Documents.Count()) End With ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''V:\RPD\401k Payments\RMD\RMD Auto Letters 'Notify user we are done. MsgBox("Mail Merge Complete.", vbMsgBoxSetForeground) ' Release references. wrdSelection = Nothing oDoc = Nothing End Sub ''' &lt;summary&gt; ''' create the mail merge document with the merge fields ''' &lt;/summary&gt; ''' &lt;remarks&gt;&lt;/remarks&gt; Public Sub CreateMailMergeDataFile(ByVal dayDate, ByVal hoursDate, ByVal minsDate, ByVal secondsDate) Dim wrdDataDoc As Word.Document Dim iCount As Integer ' thisDocName = "U:\Backup_RMD_Files\Merge_bkp_" + currentField27 + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + _ ' minsDate(+"_" + secondsDate + "." + "doc") thisDocName = "V:\Shardata\Backup_RMD_Files\Merge_bkp_" + currentField27 + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + _ minsDate + "_" + secondsDate + "." + "doc" oDoc.MailMerge.CreateDataSource(Name:=thisDocName, _ HeaderRecord:="FirstName,LastName,SSN,Addr1,Planno,Addr2,RMD1000,needComma, RMDAmount, x, y, z, a, NameFirst, NameLast, Addr1_2, Addr2_2,Addr3_2, Addr4_2, Addr5_2,City_2,State_2,Zip_2") wrdDataDoc = oWord.Documents.Open(thisDocName) For iCount = 1 To 1 wrdDataDoc.Tables(1).Rows.Add() Next (iCount) If currentField24 = "rmd1000" Then MsgBox("is the file on the network complete?") Else End If If currentField24 = Nothing Then Else currentField24a = "," End If If currentField24 = "$" Then
currentField24a = ""
Else
If currentField25 < 1000 Then
currentField24a = ""
End If
End If
FillRow(wrdDataDoc, 3, currentField15, currentField14, currentField27, currentField16, currentField28, currentField17, currentField24, currentField24a, currentField25, currentField26, currentField27, currentField25, currentField1, currentField30, currentField29, currentField31, currentField32, currentField33, currentField34, currentField35, currentField36, currentField37, currentField38)
End Sub
''' &lt;summary&gt;
''' insert blank lines in the document
''' &lt;/summary&gt;
''' &lt;param name="LineNum"&gt;&lt;/param&gt;
''' &lt;remarks&gt;&lt;/remarks&gt;
Public Sub InsertLines(ByVal LineNum As Integer)
Dim iCount As Integer
For iCount = 1 To LineNum
oWord.Selection.TypeParagraph()
Next (iCount)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' &lt;/summary&gt;' &lt;param name="Doc"&gt;&lt;/param&gt;     '&lt;param name="Row"&gt;&lt;/param&gt;     ' &lt;param name="Text1"&gt;&lt;/param&gt;
' &lt;param name="Text2"&gt;&lt;/param&gt; &lt;param name="Text3"&gt;&lt;/param&gt; &lt;param name="Text4"&gt;&lt;/param&gt; &lt;param name="text5"&gt;&lt;/param&gt;
' &lt;param name="text6"&gt;&lt;/param&gt; &lt;param name="text7"&gt;&lt;/param&gt; &lt;param name="text8"&gt;&lt;/param&gt; &lt;param name="text9"&gt;&lt;/param&gt;
' &lt;param name="text10"&gt;&lt;/param&gt; &lt;param name="text11"&gt;&lt;/param&gt; &lt;param name="text12"&gt;&lt;/param&gt; &lt;param name="text13"&gt;&lt;/param&gt;
' &lt;param name="text14"&gt;&lt;/param&gt; &lt;param  name="text15"&gt;&lt;/param&gt; &lt;param name="text16"&gt;&lt;/param&gt;    ' &lt;param name="text17"&gt;&lt;/param&gt;
' &lt;param name="text18"&gt;&lt;/param&gt;    ' &lt;param name="text19"&gt;&lt;/param&gt;
' &lt;param name="text20"&gt;&lt;/param&gt;    ' &lt;param name="text21"&gt;&lt;/param&gt;
' &lt;param name="text22"&gt;&lt;/param&gt;    ' &lt;param name="text23"&gt;&lt;/param&gt;     ' &lt;remarks&gt;&lt;/remarks&gt;
Public Sub FillRow(ByVal Doc As Word.Document, ByVal Row As Integer, _
ByVal Text1 As String, ByVal Text2 As String, ByVal Text3 As String, _
ByVal Text4 As String, ByVal text5 As String, ByVal text6 As String, _
ByVal text7 As String, ByVal text8 As String, ByVal text9 As String, _
ByVal text10 As String, ByVal text11 As String, ByVal text12 As String, _
ByVal text13 As String, ByVal text14 As String, ByVal text15 As String, _
ByVal text16 As String, ByVal text17 As String, ByVal text18 As String, _
ByVal text19 As String, ByVal text20 As String, ByVal text21 As String, ByVal text22 As String, ByVal text23 As String)
' Insert the data into the specific cell.
With Doc.Tables(1)
.Cell(Row, 1).Range.InsertAfter(Text1)       ' first name
.Cell(Row, 2).Range.InsertAfter(Text2)       ' last name
.Cell(Row, 3).Range.InsertAfter(Text3)       ' ssn
.Cell(Row, 5).Range.InsertAfter(text5)       ' plan no
.Cell(Row, 7).Range.InsertAfter(text7)       ' dollars             thousands()
.Cell(Row, 8).Range.InsertAfter(text8)       ' comma or no             comma()
.Cell(Row, 9).Range.InsertAfter(text9)       ' rmd amount less than $1,000 .Cell(Row, 10).Range.InsertAfter(text10) ' rmd factor .Cell(Row, 11).Range.InsertAfter(text11) ' ssn .Cell(Row, 12).Range.InsertAfter(text12) ' rmd amount less than 1,000 .Cell(Row, 13).Range.InsertAfter(text13) 'month/day/year .Cell(Row, 14).Range.InsertAfter(text14) ' first name .Cell(Row, 15).Range.InsertAfter(text15) ' last name .Cell(Row, 16).Range.InsertAfter(text16) ' addr1 .Cell(Row, 17).Range.InsertAfter(text17) ' addr2 .Cell(Row, 18).Range.InsertAfter(text18) ' addr3 .Cell(Row, 19).Range.InsertAfter(text19) ' addr4 .Cell(Row, 20).Range.InsertAfter(text20) ' addr5 .Cell(Row, 21).Range.InsertAfter(text21) ' city .Cell(Row, 22).Range.InsertAfter(text22) ' state .Cell(Row, 23).Range.InsertAfter(text23) ' zip End With End Sub ' &lt;summary&gt; ' read the file created by the VBA in the Omni Station ' &lt;/summary&gt; ' &lt;param name="daydate"&gt;&lt;/param&gt; ' &lt;param name="hoursDate"&gt;&lt;/param&gt; ' &lt;param name="minsDate"&gt;&lt;/param&gt; ' &lt;param name="secondsDate"&gt;&lt;/param&gt; ' &lt;remarks&gt;&lt;/remarks&gt; ' Public Sub Read_File(ByVal showDate As Date, ByVal daydate As String, ByVal hoursDate As String, ByVal minsDate As String, ByVal secondsDate As String) Public Sub read_file(ByVal daydate As String, ByVal hoursDate As String, ByVal minsDate As String, ByVal secondsDate As String) Dim currentField As String Dim curField As String Dim docName As String ' Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("U:\rmd\FileForMailMerge.txt") Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("V:\Shardata\FileForMailMerge.txt") myreader.TextFieldType = FileIO.FieldType.Delimited myreader.SetDelimiters("@") Dim currentRow As String() While Not myreader.EndOfData Try currentRow = myreader.ReadFields() For Each currentField In currentRow whichField = 0 For Each curField In Split(currentField, "@") whichField = whichField + 1 If whichField = 1 Then currentField1 = curField 'date End If If whichField = 2 Then currentField2 = curField 'blank End If If whichField = 3 Then currentField3 = curField 'month End If If whichField = 4 Then currentField4 = curField 'day End If If whichField = 5 Then currentField5 = curField 'year End If If whichField = 6 Then currentField6 = curField 'month End If If whichField = 7 Then currentField7 = curField 'day End If If whichField = 8 Then currentField8 = curField 'year End If If whichField = 9 Then currentField9 = curField 'month End If If whichField = 10 Then currentField10 = curField 'day End If If whichField = 11 Then currentField11 = curField 'year End If If whichField = 12 Then currentField12 = curField 'day End If If whichField = 13 Then currentField13 = curField 'year End If If whichField = 14 Then If currentField14 = "lname" Then 'last name Dim lnameField As String Dim nameKount As Integer nameKount = 0 For Each lnameField In Split(curField, ",") nameKount = nameKount + 1 ' MsgBox(curField) If nameKount = 1 Then currentField14 = lnameField 'date currentField29 = currentField14 lname_length = (Trim(currentField14.Length)) End If If nameKount = 2 Then currentField15 = Trim(lnameField) currentField30 = currentField15 'first name fname_length = (Trim(currentField15.Length)) End If Next End If If currentField15 = "" Then currentField14 = curField 'lname currentField29 = currentField14 lname_length = (Trim(currentField14.Length)) End If End If If whichField = 15 Then If currentField14 = "lname" And currentField15 = "" Then currentField15 = Trim(curField) 'fname currentField30 = currentField15 fname_length = (Trim(currentField15.Length)) Else whichField = whichField + 1 End If End If If whichField = 16 Then currentField16 = Trim(curField) 'addr1 addr_length = Trim(currentField16.Length) End If If whichField = 17 Then currentField17 = curField 'addr2 End If If whichField = 18 Then currentField18 = curField 'addr3 End If If whichField = 19 Then currentField19 = curField 'addr4 End If If whichField = 20 Then currentField20 = curField 'addr5 End If If whichField = 21 Then currentField21 = curField 'city End If If whichField = 22 Then currentField22 = curField 'state End If If whichField = 23 Then currentField23 = curField 'zip End If ' ' If whichField = 24 Then 'currentField24 = curField 'rmd1000 If curField <> "rmd1000" Then whichField = whichField + 1 currentField24 = "" Else currentField24 = curField End If End If If whichField = 25 Then currentField25 = curField 'rmdamount End If If whichField = 26 Then currentField26 = curField 'rmd factor End If If whichField = 27 Then currentField27 = Trim(curField) 'ssn If currentField27 = "ssn" Then Else currentField39 = currentField27.Substring(7, 4) currentField27 = "xxx-xx-" + currentField39 End If End If If whichField = 28 Then currentField28 = curField 'planNo End If If whichField = 25 Then currentField25 = curField 'rmd amount End If If whichField = 14 Then If currentField14 = "lname" Then currentField29 = "NameLast" Else currentField29 = currentField14 End If End If If whichField = 15 Then If currentField15 = "fname" Then currentField30 = "NameFirst" Else currentField30 = currentField15 End If End If If whichField = 16 Then If currentField16 = "addr1" Then currentField31 = "Addr1_2" Else currentField31 = currentField16 End If End If If whichField = 17 Then If currentField17 = "addr2" Then currentField32 = "Addr2_2" Else 'currentField32 = currentField17 'take empty spaces out of the address currentField32 = Replace(currentField17, " ", " ") 'take empty spaces out of the address currentField32 = Replace(currentField32, " ", " ") 'take empty spaces out of the address 'currentField32 = currentField32 + "" End If End If If whichField = 18 Then If currentField18 = "addr3" Then currentField33 = "Addr3_2" Else currentField33 = currentField18 currentField33 = Replace(currentField18, " ", " ") 'take empty spaces out of the address currentField33 = Replace(currentField33, " ", " ") 'take empty spaces out of the address End If End If If whichField = 19 Then If currentField19 = "addr4" Then currentField34 = "Addr4_2" Else currentField34 = currentField19 currentField34 = Replace(currentField19, " ", " ") 'take empty spaces out of the address currentField34 = Replace(currentField34, " ", " ") 'take empty spaces out of the address End If End If If whichField = 20 Then If currentField20 = "addr5" Then currentField35 = "Addr5_2" Else currentField35 = currentField20 End If End If If whichField = 21 Then If currentField21 = "city" Then currentField36 = "City_2" Else currentField36 = currentField21 + ", " End If End If If whichField = 22 Then If currentField22 = "state" Then currentField37 = "State_2" Else currentField37 = currentField22 + "" End If End If If whichField = 23 Then If currentField23 = "zip" Then currentField38 = "Zip_2" Else currentField38 = currentField23 End If End If If whichField = 29 Then currentField41 = curField 'plan If currentField28 = "" Then currentField28 = currentField41 End If ' currentField39 = curField 'full SSN currentField39 = currentField27.Substring(7, 4) currentField27 = "xxx-xx-" + currentField39 End If If whichField = 30 Then ' currentField30 = 30 Then 'plan no End If If whichField = 31 Or whichField = 30 Then ' currentField31 = 31 Then 'ssn End If If whichField = 31 Or whichField = 32 Then currentField40 = curField 'participant AGE End If Next Next Catch ex As Microsoft.VisualBasic. FileIO.MalformedLineException MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While End Using ' docName = "U:\Backup_RMD_Files\Merge_bkup_" + Trim(currentField27) + "_" + currentField28 + "_" + daydate + "_" + hoursDate + "_" + _ ' minsDate(+"_" + secondsDate + "." + "doc") docName = "V:\Shardata\Backup_RMD_Files\Merge_bkup_" + Trim(currentField27) + "_" + currentField28 + "_" + daydate + "_" + hoursDate + "_" + _ minsDate + "_" + secondsDate + "." + "doc" currentField28 = Trim(currentField28) spouse_10_yrs_younger(currentField40) 'FileCopy("U:\rmd\FileForMailMerge.txt", docName + "_input_file") ' FileCopy("V:\Shardata\rmd\FileForMailMerge.txt", docName + "_input_file") FileCopy("V:\Shardata\FileForMailMerge.txt", docName + "_input_file") ' xxxxx.BinarySearch(currentField39, sp_ssn) ' Dim spouseCheck As Integer = 0 ' spouseCheck = xxxxx.IndexOf(currentField39) End Sub Sub spouse_10_yrs_younger(ByVal age) ' Dim rmdFactor(20, 30) As Double 'rmdFactor(1, 1) = 19 rmdFactor(1, 2) = 19 rmdFactor(1, 3) = 19 rmdFactor(1, 4) = 19 'rmdFactor(1, 5) = 19 rmdFactor(1, 6) = 19 rmdFactor(1, 7) = 19 rmdFactor(1, 8) = 19 'rmdFactor(1, 9) = 19 rmdFactor(1, 10) = 19 rmdFactor(1, 11) = 19 rmdFactor(1, 12) = 19 'rmdFactor(1, 13) = 19 rmdFactor(1, 14) = 19 rmdFactor(1, 15) = 19 rmdFactor(1, 16) = 19 'rmdFactor(1, 17) = 19 rmdFactor(1, 18) = 19 rmdFactor(1, 19) = 19 rmdFactor(1, 20) = 19 'rmdFactor(1, 21) = 19 rmdFactor(1, 22) = 19 rmdFactor(1, 23) = 19 rmdFactor(1, 24) = 19 'rmdFactor(1, 25) = 19 rmdFactor(1, 26) = 19 rmdFactor(1, 27) = 19 rmdFactor(1, 28) = 19 'rmdFactor(1, 29) = 19 rmdFactor(1, 30) = 19 'rmdFactor(2, 1) = 19 rmdFactor(2, 2) = 19 rmdFactor(2, 3) = 19 rmdFactor(2, 4) = 19 'rmdFactor(2, 5) = 19 rmdFactor(2, 6) = 19 rmdFactor(2, 7) = 19 rmdFactor(2, 8) = 19 'rmdFactor(2, 9) = 19 rmdFactor(2, 10) = 19 rmdFactor(2, 11) = 19 rmdFactor(2, 12) = 19 'rmdFactor(2, 13) = 19 rmdFactor(2, 14) = 19 rmdFactor(2, 15) = 19 rmdFactor(2, 16) = 19 'rmdFactor(2, 17) = 19 rmdFactor(2, 18) = 19 rmdFactor(2, 19) = 19 rmdFactor(2, 20) = 19 'rmdFactor(2, 21) = 19 rmdFactor(2, 22) = 19 rmdFactor(2, 23) = 19 rmdFactor(2, 24) = 19 'rmdFactor(2, 25) = 19 rmdFactor(2, 26) = 19 rmdFactor(2, 27) = 19 rmdFactor(2, 28) = 19 'rmdFactor(2, 29) = 19 rmdFactor(2, 30) = 19 'rmdFactor(2, 1) = 19 rmdFactor(2, 2) = 19 rmdFactor(2, 3) = 19 rmdFactor(2, 4) = 19 'rmdFactor(2, 5) = 19 rmdFactor(2, 6) = 19 rmdFactor(2, 7) = 19 rmdFactor(2, 8) = 19 'rmdFactor(2, 9) = 19 rmdFactor(2, 10) = 19 rmdFactor(2, 11) = 19 rmdFactor(2, 12) = 19 'rmdFactor(2, 13) = 19 rmdFactor(2, 14) = 19 rmdFactor(2, 15) = 19 rmdFactor(2, 16) = 19 'rmdFactor(2, 17) = 19 rmdFactor(2, 18) = 19 rmdFactor(2, 19) = 19 rmdFactor(2, 20) = 19 'rmdFactor(2, 21) = 19 rmdFactor(2, 22) = 19 rmdFactor(2, 23) = 19 rmdFactor(2, 24) = 19 'rmdFactor(2, 25) = 19 rmdFactor(2, 26) = 19 rmdFactor(2, 27) = 19 rmdFactor(2, 28) = 19 'rmdFactor(2, 29) = 19 rmdFactor(2, 30) = 19 ' Dim x As ArrayList 'Select Case age ' Case 70.0 ' Case 71.0 ' Case 72.0 ' Case 73.0 ' Case 74.0 ' Case 75.0, 75.5 ' Case 75.0, 75.08, 75.12, 75.25, 75.33, 75.41, 75.5, 75.58, 75.64, 75.72, 75.8, 75.88, 75.96 ' Case 76.0, 76.08, 76.12, 76.25, 76.33, 76.41, 76.5, 76.58, 76.64, 76.72, 76.8, 76.88, 76.96 ' Case 77.0, 77.08, 77.12, 77.25, 77.33, 77.41, 77.5, 77.58, 77.64, 77.72, 77.8, 77.88, 77.96 ' Case 78.0, 78.08, 78.12, 78.25, 78.33, 78.41, 78.5, 78.58, 78.64, 78.72, 78.8, 78.88, 78.96 ' Case 79.0, 79.08, 79.12, 79.25, 79.33, 79.41, 79.5, 79.58, 79.64, 79.72, 79.8, 79.88, 79.96 ' Case 80.0, 80.08, 80.12, 80.25, 80.33, 80.41, 80.5, 80.58, 80.64, 80.72, 80.8, 80.88, 80.96 ' Case 77.0, 77.08, 77.12, 77.25, 77.33, 77.41, 77.5, 77.58, 77.64, 77.72, 77.8, 77.88, 77.96 ' Case 78.0, 78.08, 78.12, 78.25, 78.33, 78.41, 78.5, 78.58, 78.64, 78.72, 78.8, 78.88, 78.96 'Case 77.0 Case 78.0 Case 79.0 Case 80.0 Case 81.0 Case 82.0 Case 83.0 Case 84.0 Case 85.0 Case 86.0 Case 87.0 'Case 88.0 Case 89.0 Case 90.0 Case 91.0 Case 92.0 Case 93.0 'End Select ' Select [ Case ] testexpression '[ Case expressionlist ' [ statements ] ] '[ Case Else ' [ elsestatements ] ] ' End Select 'Dim number As Integer = 8 'Select Case number ' Case 1 To 5 ' Debug.WriteLine("Between 1 and 5, inclusive") ' ' The following is the only Case clause that evaluates to True. ' Case 6, 7, 8 ' Debug.WriteLine("Between 6 and 8, inclusive") ' Case 9 To 10 ' Debug.WriteLine("Equal to 9 or 10") ' Case Else ' Debug.WriteLine("Not between 1 and 10, inclusive") 'End Select 'Select Case currentField26 ' Case 12.0 ' Case 22.0 ' Case 22.9 ' Case 23.8 ' Case 24.7 ' Case 25.6 ' Case 26.5 'End Select 'If currentField26 = "" Then 'End If ' If '70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: '40: 44.0 44.0 43.9 43.9 43.9 43.8 43.8 43.8 43.8 43.8 43.7 '41: 43.1 43.0 43.0 43.0 42.9 42.9 42.9 42.9 42.8 42.8 42.8 '42: 42.2 42.1 42.1 42.0 42.0 42.0 41.9 41.9 41.9 41.9 41.8 '43: 41.3 41.2 41.1 41.1 41.1 41.0 41.0 41.0 40.9 40.9 40.9 '44: 40.3 40.3 40.2 40.2 40.1 40.1 40.1 40.0 40.0 40.0 40.0 '45: 39.4 39.4 39.3 39.3 39.2 39.2 39.1 39.1 39.1 39.1 39.0 '46: 38.6 38.5 38.4 38.4 38.3 38.3 38.2 38.2 38.2 38.1 38.1 '47: 37.7 37.6 37.5 37.5 37.4 37.4 37.3 37.3 37.2 37.2 37.2 '48: 36.8 36.7 36.6 36.6 36.5 36.5 36.4 36.4 36.3 36.3 36.3 '49: 35.9 35.9 35.8 35.7 35.6 35.6 35.5 35.5 35.4 35.4 35.4 '50: 35.1 35.0 34.9 34.8 34.8 34.7 34.6 34.6 34.5 34.5 34.5 '51: 34.3 34.2 34.1 34.0 33.9 33.8 33.8 33.7 33.6 33.6 33.6 '52: 33.4 33.3 33.2 33.1 33.0 33.0 32.9 32.8 32.8 32.7 32.7 '53: 32.6 32.5 32.4 32.3 32.2 32.1 32.0 32.0 31.9 31.8 31.8 '54: 31.8 31.7 31.6 31.5 31.4 31.3 31.2 31.1 31.0 31.0 30.9 '55: 31.1 30.9 30.8 30.6 30.5 30.4 30.3 30.3 30.2 30.1 30.1 '56: 30.3 30.1 30.0 29.8 29.7 29.6 29.5 29.4 29.3 29.3 29.2 '57: 29.5 29.4 29.2 29.1 28.9 28.8 28.7 28.6 28.5 28.4 28.4 '58: 28.8 28.6 28.4 28.3 28.1 28.0 27.9 27.8 27.7 27.6 27.5 '59: 28.1 27.9 27.7 27.5 27.4 27.2 27.1 27.0 26.9 26.8 26.7 '60: 27.4 27.2 27.0 26.8 26.6 26.5 26.3 26.2 26.1 26.0 25.9 '61: 26.7 26.5 26.3 26.1 25.9 25.7 25.6 25.4 25.3 25.2 25.1 '62: 26.1 25.8 25.6 25.4 25.2 25.0 24.8 24.7 24.6 24.4 24.3 '63: 25.4 25.2 24.9 24.7 24.5 24.3 24.1 23.9 23.8 23.7 23.6 '64: 24.8 24.5 24.3 24.0 23.8 23.6 23.4 23.2 23.1 22.9 22.8 '65: 24.3 23.9 23.7 23.4 23.1 22.9 22.7 22.5 22.4 22.2 22.1 '66: 23.7 23.4 23.1 22.8 22.5 22.3 22.0 21.8 21.7 21.5 21.3 '67: 23.2 22.8 22.5 22.2 21.9 21.6 21.4 21.2 21.0 20.8 20.6 '68: 22.7 22.3 22.0 21.6 21.3 21.0 20.8 20.6 20.3 20.1 20.0 '69: 22.2 21.8 21.4 21.1 20.8 20.5 20.2 19.9 19.7 19.5 19.3 '70: 21.8 21.3 20.9 20.6 20.2 19.9 19.6 19.4 19.1 18.9 18.7 'Retirement Account Owner's Age (80 - 90) 'Age of Your Beneficiary Retirement Account Owner's Age (Your Age) '80:81:82:83:84:85:86:87:88:89:90: '50: 34.5 34.4 34.4 34.4 34.3 34.3 34.3 34.3 34.3 34.3 34.2 '51: 33.6 33.5 33.5 33.5 33.4 33.4 33.4 33.4 33.4 33.3 33.3 '52: 32.7 32.6 32.6 32.6 32.5 32.5 32.5 32.5 32.5 32.4 32.4 '53: 31.8 31.8 31.7 31.7 31.7 31.6 31.6 31.6 31.6 31.5 31.5 '54: 30.9 30.9 30.8 30.8 30.8 30.7 30.7 30.7 30.7 30.7 30.6 '55: 30.1 30.0 30.0 29.9 29.9 29.9 29.8 29.8 29.8 29.8 29.8 '56: 29.2 29.2 29.1 29.1 29.0 29.0 29.0 28.9 28.9 28.9 28.9 '57: 28.4 28.3 28.3 28.2 28.2 28.1 28.1 28.1 28.0 28.0 28.0 '58: 27.5 27.5 27.4 27.4 27.3 27.3 27.2 27.2 27.2 27.2 27.1 '59: 26.7 26.6 26.6 26.5 26.5 26.4 26.4 26.4 26.3 26.3 26.3 '60: 25.9 25.8 25.8 25.7 25.6 25.6 25.5 25.5 25.5 25.4 25.4 '61: 25.1 25.0 24.9 24.9 24.8 24.8 24.7 24.7 24.6 24.6 24.6 '62: 24.3 24.2 24.1 24.1 24.0 23.9 23.9 23.8 23.8 23.8 23.7 '63: 23.6 23.4 23.4 23.3 23.2 23.1 23.1 23.0 23.0 22.9 22.9 '64: 22.8 22.7 22.6 22.5 22.4 22.3 22.3 22.2 22.2 22.1 22.1 '65: 22.1 21.9 21.8 21.7 21.6 21.6 21.5 21.4 21.4 21.3 21.3 '66: 21.3 21.2 21.1 21.0 20.9 20.8 20.7 20.7 20.6 20.5 20.5 '67: 20.6 20.5 20.4 20.2 20.1 20.1 20.0 19.9 19.8 19.8 19.7 '68: 20.0 19.8 19.7 19.5 19.4 19.3 19.2 19.2 19.1 19.0 19.0 '69: 19.3 19.1 19.0 18.8 18.7 18.6 18.5 18.4 18.3 18.3 18.2 '70: 18.7 18.5 18.3 18.2 18.0 17.9 17.8 17.7 17.6 17.6 17.5 '71: 18.1 17.9 17.7 17.5 17.4 17.3 17.1 17.0 16.9 16.9 16.8 '72: 17.5 17.3 17.1 16.9 16.7 16.6 16.5 16.4 16.3 16.2 16.1 '73: 16.9 16.7 16.5 16.3 16.1 16.0 15.8 15.7 15.6 15.5 15.4 '74: 16.4 16.2 15.9 15.7 15.5 15.4 15.2 15.1 15.0 14.9 14.8 '75: 15.9 15.6 15.4 15.2 15.0 14.8 14.6 14.5 14.4 14.3 14.2 '76: 15.4 15.1 14.9 14.7 14.4 14.3 14.1 13.9 13.8 13.7 13.6 '77: 15.0 14.7 14.4 14.2 13.9 13.7 13.5 13.4 13.2 13.1 13.0 '78: 14.5 14.2 13.9 13.7 13.4 13.2 13.0 12.9 12.7 12.6 12.4 '79: 14.1 13.8 13.5 13.2 13.0 12.8 12.5 12.4 12.2 12.0 11.9 '80: 13.8 13.4 13.1 12.8 12.6 12.3 12.1 11.9 11.7 11.5 11.4 '80:81:82:83:84:85:86:87:88:89:90: '50: 34.5 34.4 34.4 34.4 34.3 34.3 34.3 34.3 34.3 34.3 34.2 '51: 33.6 33.5 33.5 33.5 33.4 33.4 33.4 33.4 33.4 33.3 33.3 '52: 32.7 32.6 32.6 32.6 32.5 32.5 32.5 32.5 32.5 32.4 32.4 '53: 31.8 31.8 31.7 31.7 31.7 31.6 31.6 31.6 31.6 31.5 31.5 '54: 30.9 30.9 30.8 30.8 30.8 30.7 30.7 30.7 30.7 30.7 30.6 '55: 30.1 30.0 30.0 29.9 29.9 29.9 29.8 29.8 29.8 29.8 29.8 '56: 29.2 29.2 29.1 29.1 29.0 29.0 29.0 28.9 28.9 28.9 28.9 '57: 28.4 28.3 28.3 28.2 28.2 28.1 28.1 28.1 28.0 28.0 28.0 '58: 27.5 27.5 27.4 27.4 27.3 27.3 27.2 27.2 27.2 27.2 27.1 '59: 26.7 26.6 26.6 26.5 26.5 26.4 26.4 26.4 26.3 26.3 26.3 '60: 25.9 25.8 25.8 25.7 25.6 25.6 25.5 25.5 25.5 25.4 25.4 '61: 25.1 25.0 24.9 24.9 24.8 24.8 24.7 24.7 24.6 24.6 24.6 '62: 24.3 24.2 24.1 24.1 24.0 23.9 23.9 23.8 23.8 23.8 23.7 '63: 23.6 23.4 23.4 23.3 23.2 23.1 23.1 23.0 23.0 22.9 22.9 '64: 22.8 22.7 22.6 22.5 22.4 22.3 22.3 22.2 22.2 22.1 22.1 '65: 22.1 21.9 21.8 21.7 21.6 21.6 21.5 21.4 21.4 21.3 21.3 '66: 21.3 21.2 21.1 21.0 20.9 20.8 20.7 20.7 20.6 20.5 20.5 '67: 20.6 20.5 20.4 20.2 20.1 20.1 20.0 19.9 19.8 19.8 19.7 '68: 20.0 19.8 19.7 19.5 19.4 19.3 19.2 19.2 19.1 19.0 19.0 '69: 19.3 19.1 19.0 18.8 18.7 18.6 18.5 18.4 18.3 18.3 18.2 '70: 18.7 18.5 18.3 18.2 18.0 17.9 17.8 17.7 17.6 17.6 17.5 '71: 18.1 17.9 17.7 17.5 17.4 17.3 17.1 17.0 16.9 16.9 16.8 '72: 17.5 17.3 17.1 16.9 16.7 16.6 16.5 16.4 16.3 16.2 16.1 '73: 16.9 16.7 16.5 16.3 16.1 16.0 15.8 15.7 15.6 15.5 15.4 '74: 16.4 16.2 15.9 15.7 15.5 15.4 15.2 15.1 15.0 14.9 14.8 '75: 15.9 15.6 15.4 15.2 15.0 14.8 14.6 14.5 14.4 14.3 14.2 '76: 15.4 15.1 14.9 14.7 14.4 14.3 14.1 13.9 13.8 13.7 13.6 '77: 15.0 14.7 14.4 14.2 13.9 13.7 13.5 13.4 13.2 13.1 13.0 '78: 14.5 14.2 13.9 13.7 13.4 13.2 13.0 12.9 12.7 12.6 12.4 '79: 14.1 13.8 13.5 13.2 13.0 12.8 12.5 12.4 12.2 12.0 11.9 '80: 13.8 13.4 13.1 12.8 12.6 12.3 12.1 11.9 11.7 11.5 11.4 End Sub 'Sub load_appconfig(ByVal sAttr) Sub load_appconfig() 'Dim sAttr As String ' sAttr = ConfigurationSettings.AppSettings("Key0") 'sAttr = ConfigurationSettings.AppSettings("Key0") ' Dim sAll As NameValueCollection ' sAll = ConfigurationSettings.AppSettings() 'sAttr = System.Configuration!System.Configuration.ConfigurationManager.AppSettings("Key0") ' sAttr = ConfigurationSettings.AppSettings("Key0") ' sAll = ConfigurationSettings.AppSettings() ' System.Configuration.ConfigurationManager.AppSettings 'Dim x As ArrayList Dim rmdFactor(20, 30) As Double ' Dim x As ArrayList Dim sAttr As String ' sAttr = System.Configuration.ConfigurationManager.AppSettings("Key0") sAttr = System.Configuration.ConfigurationManager.AppSettings("Spouse10Year") ' Dim xxx As String = System.Configuration.ConfigurationManager.AppSettings("KeyName") Dim xxx As String = System.Configuration.ConfigurationManager.AppSettings("Spouse10Year") Console.WriteLine("The value of Key0: " & sAttr) Dim sAll As NameValueCollection sAll = System.Configuration.ConfigurationManager.AppSettings() Dim fieldSSN As String Dim fieldPlan As String Dim fieldDOB As String Dim s As String ' Dim xxxx As ArrayList For Each s In sAll.AllKeys Dim xxxx As New ArrayList Console.WriteLine("Key: " & s & " Value: " & sAll(s)) Dim spouse_rmd = New spouse() Dim fieldNo As Integer = 0 For Each spouseField In Split(sAll(s), ",") fieldNo = fieldNo + 1 If fieldNo = 1 Then fieldSSN = spouseField spouse_rmd.sp_ssn = fieldSSN End If If fieldNo = 2 Then fieldPlan = spouseField spouse_rmd.sp_plan = spouseField End If If fieldNo = 3 Then fieldDOB = spouseField spouse_rmd.spouseDOB = spouseField End If Next 'spouse = New spouse(fieldSSN, fieldPlan, fieldDOB) ' spouse_rmd = New spouse() xxxx.Add(spouse_rmd) 'spouseField)) ' Next Next ' Console.ReadLine() 'Dim lnameField As String 'Dim nameKount As Integer 'nameKount = 0 'For Each lnameField In Split(curField, ",") ' xxxxx = xxxx End Sub ' Public Class spouse(fieldSSN,fieldPlan,fieldDOB) Public Class spouse Friend plan As String Property sp_plan() As String Get Return plan End Get Set(ByVal value As String) plan = value End Set End Property Friend ssn As String Property sp_ssn() As String Get Return ssn End Get Set(ByVal value As String) ssn = value End Set End Property Public spouseDOB As String Property sp_spouseDOB() As String Get Return spouseDOB End Get Set(ByVal Value As String) spouseDOB = Value End Set End Property 'ReadOnly Property Length() As Integer ' Get ' Dim val = plan + "," + ssn + "," + spouseDOB ' Return val.Length ' End Get 'End Property End Class ' For Each lnameField In Split(curField, ",") End Module 0 Question by:inteliarchs [X] ###### Welcome to Experts Exchange Add your voice to the tech community where 5M+ people just like you are talking about what matters. • Help others & share knowledge • Earn cash & points • Learn & ask questions • 7 • 6 14 Comments LVL 76 Expert Comment ID: 36591473 OMG. I certainly think that you need some advice. But where to start? I have found this line in your code: oDoc = oWord.Documents.Add which creates a new document based on the Normal template. The default paragraph style is also, independently, called Normal and the default vertical spacing between paragraphs for that style was increased between Word 2003 and Word 2007. If this is your problem, then you could modify the style for the Normal template. However, you could change it in your code for the new document, so: oDoc.Styles("Normal").ParagraphFormat.SpaceAfter = 0 0 Author Comment ID: 36595682 I understand I do need help on how this application should be structured also, I have never written a Mail Merge application and VB.NET is not my primary language. That said any assistance would be greatly appreciated. I will make the changes that you have suggested. 0 LVL 76 Expert Comment ID: 36599662 There are a few coding improvements that could be made, and which I have worked on . 1. I've created variables for the folder names in one place, so that maintenance will be easier. 2. I've removed some of the commented-out code which was confusing things. 3. You have used the '+' operator, instead of '&' to concatenate strings in the file names. If some of the elements to be concatenated are numeric, a 'Cast' error occurs, because the numerical parts are added together, but cannot be added to non-numeric strings. 4. You have used about 40 similar variables like currentField1. An array is better, because you have to do the same thing with many of them. I have use a Select case construct to do that. I have used an Enum for the indexes, so that the array elements are understandable. 5. It is optional to name the object in the Next line that ends a For each block, but it is much easier to maintain if you do put the name in. 6. You have made very heavy weather of formatting a date. It can be done in one line: strMyFormat = MyDate.ToString("dd_hh_nn_ss") so I have passed the date as a single variable in a couple of places, insted of the days, hours, minutes, seconds Imports Microsoft.Office.Interop.Word Imports System.Configuration Imports System.IO 'Imports System.Configuration.ConfigurationManager 'Imports System.Configuration.ConfigurationErrorsException'Dim wdExtend As Object = Microsoft.Office.Interop.Word.WdUnits.wdExtend Imports System.Collections.Specialized Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.Access Imports Microsoft.Vbe.Interop 'Imports Microsoft.Vbe.Interop.Forms.dll 'Imports Microsoft.Office.Interop.Word 'Acrobat Reader parameters Imports System.Net Imports System.Net.Sockets 'Imports Microsoft.WindowsMediaServices.Interop Imports System.Runtime.InteropServices Module Module1 Enum fldType '<---- GLS date1 '<---- GLS blank '<---- GLS month1 '<---- GLS day1 '<---- GLS year1 '<---- GLS Month2 '<---- GLS day2 '<---- GLS year2 '<---- GLS Month3 '<---- GLS day3 '<---- GLS year3 '<---- GLS day4 '<---- GLS year4 '<---- GLS lnam '<---- GLS fname '<---- GLS addr01 '<---- GLS addr02 '<---- GLS addr03 '<---- GLS addr04 '<---- GLS addr05 '<---- GLS city0 '<---- GLS state0 '<---- GLS zip0 '<---- GLS rmd1000 '<---- GLS rmd1000Command '<---- GLS rmdAmount '<---- GLS rmdFactor '<---- GLS ssn '<---- GLS planNo '<---- GLS nameFirst '<---- GLS nameLast '<---- GLS addr11 '<---- GLS addr12 '<---- GLS addr13 '<---- GLS addr14 '<---- GLS addr15 '<---- GLS city1 '<---- GLS state1 '<---- GLS zip1 '<---- GLS ssnWorkarea '<---- GLS participantAge '<---- GLS qPlanNo '<---- GLS End Enum '<---- GLS Dim pExportFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF Dim sExportFilePath As String = "" Dim paramOpenAfterExport As Boolean = False Dim paramExportOptimizeFor As WdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint Dim paramExportRange As WdExportRange = WdExportRange.wdExportAllDocument Dim paramStartPage As Int32 = 2 Dim paramEndPage As Int32 = 2 Dim paramExportItem As WdExportItem = WdExportItem.wdExportDocumentContent Dim paramIncludeDocProps As Boolean = True Dim paramKeepIRM As Boolean = True Dim paramCreateBookmarks As WdExportCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks Dim paramDocStructureTags As Boolean = True Dim paramBitmapMissingFonts As Boolean = True Dim paramUseISO19005_1 As Boolean = False Dim wdline As Object = Microsoft.Office.Interop.Word.WdUnits.wdLine Dim wdCharacter As Object = Microsoft.Office.Interop.Word.WdUnits.wdCharacter Dim sAttrX As String 'for appconfig Dim addr_length As Integer Dim lname_length As Integer Dim fname_length As Integer Dim CurrentFields(fldType.qPlanNo) As String ' ?plan no Dim args As String() Dim oDoc As Document = Nothing Dim thisDocName As String 'Font.Name = "Arial Unicode MS" Dim oWord As Word.Application Dim whichField As Integer Dim xxxxx As ArrayList 'Dim strDataFolder As String = "V:\Shardata\" '<----- GLS Dim strDataFolder As String = "I:\Allwork\ee\27324191\" '<----- GLS Dim strBackUpSubFolder As String = "Backup_RMD_Files\" '<----- GLS 'Dim strExportFolder = "V:\RPD\401k Payments\RMD\RMD Auto Letters\" '<----- GLS Dim strExportFolder = "I:\Allwork\ee\27324191\Export\" '<----- GLS Sub Main() Dim index As Integer = 0 Dim icmpHeaderBufferIndex As Int32 = 0 Dim testDate As DateTime = Now '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' read_file(testDate) Dim sDocPath As String = "" Dim wrdSelection As Word.Selection wrdSelection = Nothing Dim StrToAdd As String StrToAdd = Nothing oWord = CreateObject("Word.Application") oWord.Visible = True oDoc = oWord.Documents.Add oDoc.Select() wrdSelection = oWord.Selection oDoc.PageSetup.LeftMargin = 92.925 oDoc.Range.Font.Name = "Courier" oDoc.Range.Font.Size = "9.0" CreateMailMergeDataFile(testDate) ''''''''''''''''''''' ' Insert merge data. '''''''''''''''''''''''''''''''''''''''''''' wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft wrdSelection.ParagraphFormat.Alignment = Word.WdWrapType.wdWrapInline '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft Dim myImage As String myImage = strDataFolder & "nreca_logo_4.png" '<----- GLS '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.InlineShapes.AddPicture(myImage) Dim strDateMMMMddyyyy As String 'used for date, ie September 13, 2011 strDateMMMMddyyyy = Now.ToString("MMMM d, yyyy") 'used for date, e.g. September 13, 2011 Dim xDateLength As Integer xDateLength = strDateMMMMddyyyy.Length() Dim iii, iiii As Integer iiii = 62 - xDateLength For iii = 1 To iiii wrdSelection.TypeText(" ") Next iii wrdSelection.InsertDateTime(DateTimeFormat:="MMMM dd, yyyy", InsertAsField:=False) wrdSelection.TypeText(Text:=vbCrLf) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(CurrentFields(fldType.fname)) 'first name wrdSelection.TypeText(" ") wrdSelection.TypeText(CurrentFields(fldType.lnam)) 'last name wrdSelection.TypeText(" ") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' iii = 0 iiii = 77 - fname_length - lname_length For iii = 1 To iiii wrdSelection.TypeText(" ") Next iii ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText("SSN: ") wrdSelection.TypeText(CurrentFields(fldType.ssn)) 'xxx-xx-xssn wrdSelection.TypeText(" ") wrdSelection.TypeParagraph() wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(CurrentFields(fldType.addr01)) 'addr1 wrdSelection.TypeText(" ") iii = 0 For iii = 1 To (81 - addr_length) wrdSelection.TypeText(" ") Next iii ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText("REA #: ") wrdSelection.TypeText(CurrentFields(fldType.planNo)) 'REA or Plan No wrdSelection.TypeText(" ") wrdSelection.TypeParagraph() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(CurrentFields(fldType.addr02)) 'addr2 InsertLines(2) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify wrdSelection.TypeText("Re: Required Minimum Distribution ") InsertLines(2) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify wrdSelection.TypeText("Dear ") wrdSelection.TypeText(" ") wrdSelection.TypeText(CurrentFields(fldType.fname)) 'first name wrdSelection.TypeText(" ") wrdSelection.TypeText(CurrentFields(fldType.lnam)) 'last name wrdSelection.TypeText(": ") wrdSelection.TypeText(" ") InsertLines(2) StrToAdd = "The assets in your retirement plans cannot remain tax-deferred indefinitely. Once you reach age 70½ and retire from service, the IRS requires you to withdraw at least a minimum each year. You must take an amount known as a required minimum distribution (RMD) from all of your retirement plans except Roth IRAs. " wrdSelection.TypeText(StrToAdd) InsertLines(2) StrToAdd = "Each year, NRECA will calculate your RMD for the 401(k) Pension Plan. The RMD for a year must be withdrawn by December 31st of that year, either in a lump sum or in installments. However, if you are taking an RMD for the first time, you may delay withdrawing the RMD until April 1st of the year after you turn age 70½ (or, in some cases, after you retire). If you delay taking it until the next year, you will have to take two minimum distributions during that calendar year. This can put you in a higher tax bracket for the year, increasing the tax you owe. " wrdSelection.TypeText(StrToAdd) InsertLines(2) StrToAdd = "Since you have attained the age of 70½ this year, an RMD from your 401(k) Pension Plan account will be processed. The amount of your Required Minimum Distribution is: " wrdSelection.TypeText(StrToAdd) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(CurrentFields(fldType.rmd1000)) CurrentFields(fldType.rmdAmount) = Trim(CurrentFields(fldType.rmdAmount)) wrdSelection.TypeText(CurrentFields(fldType.rmdAmount)) 'rmd amount '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.TypeText(".") wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = " You have the option of delaying this distribution until April 1st of next year, or you can take it this year. Please indicate below your preference regarding the RMD by checking one of the boxes below: " wrdSelection.TypeText(StrToAdd) InsertLines(1) ' InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = " _ _ " wrdSelection.TypeText(StrToAdd) InsertLines(1) StrToAdd = " |_| Delay until April 1st of next Year " wrdSelection.TypeText(StrToAdd) StrToAdd = " |_| Take RMD this year " wrdSelection.TypeText(StrToAdd) ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(1) InsertLines(1) StrToAdd = "Note: If you do not return this letter with your selection, we will delay this RMD until April 1st of next year. " wrdSelection.TypeText(StrToAdd) InsertLines(2) StrToAdd = "Regardless if you elect to defer this payment or not, 10% federal withholding will be applied to your required minimum distribution unless you check the box below. " wrdSelection.TypeText(StrToAdd) InsertLines(1) ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = " _ " wrdSelection.TypeText(StrToAdd) InsertLines(1) StrToAdd = " |_| I elect not to have federal income tax withheld " wrdSelection.TypeText(StrToAdd) ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(2) StrToAdd = "Please complete the information below if you wish to receive your payment by direct deposit regardless if you defer your payment or not. You must attach a voided check as verification of your bank information. " wrdSelection.TypeText(StrToAdd) InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(1) Dim bTable As Word.Table bTable = oDoc.Tables.Add(oWord.Selection.Range, 2, 3) bTable.Style = "Table Grid" bTable.Columns.Item(1).SetWidth(125, Word.WdRulerStyle.wdAdjustNone) bTable.Columns.Item(2).SetWidth(131, Word.WdRulerStyle.wdAdjustNone) bTable.Columns.Item(3).SetWidth(269, Word.WdRulerStyle.wdAdjustNone) bTable.Cell(2, 1).Height = 30 bTable.Cell(2, 2).Height = 30 bTable.Cell(2, 3).Height = 30 bTable.Cell(1, 1).Range.Text = "Bank Routing Number" bTable.Cell(1, 2).Range.Text = "Bank Account Number" bTable.Cell(1, 3).Range.Text = "Name of your Financial Institution" With oWord.Selection .SetRange(bTable.Range.End + 1, bTable.Range.End + 1) .Collapse(Word.WdCollapseDirection.wdCollapseEnd) End With InsertLines(0) InsertLines(1) Dim cTable As Word.Table cTable = oDoc.Tables.Add(oWord.Selection.Range, 2, 4) cTable.Style = "Table Grid" cTable.Columns.Item(1).SetWidth(277, Word.WdRulerStyle.wdAdjustNone) cTable.Columns.Item(2).SetWidth(82, Word.WdRulerStyle.wdAdjustNone) cTable.Columns.Item(3).SetWidth(82, Word.WdRulerStyle.wdAdjustNone) cTable.Columns.Item(4).SetWidth(84, Word.WdRulerStyle.wdAdjustNone) cTable.Cell(2, 1).Height = 30 cTable.Cell(2, 2).Height = 30 cTable.Cell(2, 3).Height = 30 cTable.Cell(2, 4).Height = 30 cTable.Cell(1, 1).Range.Text = "Mailing Address of the Financial Institution" cTable.Cell(1, 2).Range.Text = "City" cTable.Cell(1, 3).Range.Text = "State" cTable.Cell(1, 4).Range.Text = "Zip" With oWord.Selection .SetRange(cTable.Range.End + 1, cTable.Range.End + 1) .Collapse(Word.WdCollapseDirection.wdCollapseEnd) End With InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' StrToAdd = "Please consult your personal tax advisor to determine which option is right for you. Once you have reached a decision, you should sign this letter and return it to: NRECA RPD Unit, PO Box 6127, Lincoln, NE 68506." wrdSelection.TypeText(StrToAdd) InsertLines(3) StrToAdd = "____________________________________________________ ______________" wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft wrdSelection.TypeText(StrToAdd) InsertLines(1) StrToAdd = "Name (signature required) Date " wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft wrdSelection.TypeText(StrToAdd) InsertLines(1) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft InsertLines(1) wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft StrToAdd = "Please feel free to contact the Member Contact Center at 866.673.2299 or contactcenter@nreca.coop and ask to be transferred to the 401(k) Pension Plan Unit. " wrdSelection.TypeText(StrToAdd) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' InsertLines(8) StrToAdd = " P.O. Box 6127 - Lincoln, NE 68506 - tel: 866.673.2299 - www.nreca.coop " wrdSelection.TypeText(StrToAdd) InsertLines(1) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' wrdSelection.Font.Name = "Courier" wrdSelection.Font.Size = "14.0" wrdSelection.Font.Size = "12.0" wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft InsertLines(1) oWord.InchesToPoints(0.02) oWord.MillimetersToPoints(4) InsertLines(6) InsertLines(3) StrToAdd = " " wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(CurrentFields(fldType.nameLast)) 'first name wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(" ") StrToAdd = Trim(CurrentFields(fldType.nameFirst)) wrdSelection.TypeText(StrToAdd) 'last name wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(CurrentFields(fldType.addr11)) 'addr1 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(CurrentFields(fldType.addr12)) 'addr2 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(CurrentFields(fldType.addr13)) 'addr3 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(CurrentFields(fldType.addr14)) 'addr4 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) StrToAdd = " " 'put 2 spaces in to shove the address 2 spaces to the right wrdSelection.TypeText(StrToAdd) StrToAdd = Trim(CurrentFields(fldType.addr15)) 'addr5 wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) InsertLines(1) StrToAdd = "- - - - - " wrdSelection.TypeText(StrToAdd) wrdSelection.TypeText(Text:=vbCrLf) Dim xmargin = wrdSelection.PageSetup.LeftMargin ' 92.95 Dim ymargin = wrdSelection.PageSetup.RightMargin ' 90.00 Dim tmargin = wrdSelection.PageSetup.TopMargin ' 72.00 Dim bmargin = wrdSelection.PageSetup.BottomMargin ' 72.00 wrdSelection.PageSetup.LeftMargin = 55.0 wrdSelection.PageSetup.RightMargin = 40.0 wrdSelection.PageSetup.TopMargin = 27.0 wrdSelection.PageSetup.BottomMargin = 2.0 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim docName As String docName = strDataFolder & strBackUpSubFolder & "RMD_merge_" & Trim(CurrentFields(fldType.ssn)) & "_" & CurrentFields(fldType.planNo) & "_" & testDate.ToString("dd_hh_nn_ss") & ".doc" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' With oDoc paramOpenAfterExport = False Dim und_score As String und_score = "_" pExportFormat = WdExportFormat.wdExportFormatXPS sExportFilePath = strExportFolder & Trim(CurrentFields(fldType.ssn)) & und_score & CurrentFields(fldType.planNo) & und_score & testDate.ToString("dd_hh_nn_ss") & ".docmx" '<---- GLS oDoc.ExportAsFixedFormat(sExportFilePath, _ pExportFormat, paramOpenAfterExport, _ paramExportOptimizeFor, paramExportRange, paramStartPage, _ paramEndPage, paramExportItem, paramIncludeDocProps, _ paramKeepIRM, paramCreateBookmarks, _ paramDocStructureTags, paramBitmapMissingFonts, _ paramUseISO19005_1) oDoc.SaveAs(docName) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim myMailMergeDoc As Document = oWord.Documents.Open(docName) myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName) myMailMergeDoc.MailMerge.Application.ActiveDocument.BuiltInDocumentProperties.ToString() End With With oDoc paramOpenAfterExport = False Dim und_score As String und_score = "_" pExportFormat = WdExportFormat.wdExportFormatXPS sExportFilePath = strExportFolder & Trim(CurrentFields(fldType.ssn)) & und_score & CurrentFields(fldType.planNo) & und_score & testDate.ToString("dd_hh_nn_ss") & ".docmx" oDoc.ExportAsFixedFormat(sExportFilePath, _ pExportFormat, paramOpenAfterExport, _ paramExportOptimizeFor, paramExportRange, paramStartPage, _ paramEndPage, paramExportItem, paramIncludeDocProps, _ paramKeepIRM, paramCreateBookmarks, _ paramDocStructureTags, paramBitmapMissingFonts, _ paramUseISO19005_1) oDoc.SaveAs(docName) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim myMailMergeDoc As Document = oWord.Documents.Open(docName) myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName) myMailMergeDoc.MailMerge.Application.ActiveDocument.BuiltInDocumentProperties.ToString() Dim xxx As String = myMailMergeDoc.MailMerge.Application.ActiveDocument.ProtectionType ' = WdProtectionType.wdNoProtection Dim xxxxx As String = myMailMergeDoc.MailMerge.Application.ActiveDocument.ProtectionType ' = WdProtectionType.wdNoProtection End With ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''V:\RPD\401k Payments\RMD\RMD Auto Letters 'Notify user we are done. MsgBox("Mail Merge Complete.", vbMsgBoxSetForeground) ' Release references. wrdSelection = Nothing oDoc = Nothing End Sub Public Sub CreateMailMergeDataFile(ByVal dt As Date) Dim wrdDataDoc As Word.Document Dim iCount As Integer thisDocName = strDataFolder & strBackUpSubFolder & "Merge_bkp_" & CurrentFields(fldType.ssn) & "_" & CurrentFields(fldType.planNo) & "_" & dt.ToString("dd_hh_mm_ss") _ & ".doc" '<---- GLS oDoc.MailMerge.CreateDataSource(Name:=thisDocName, _ HeaderRecord:="FirstName,LastName,SSN,Addr1,Planno,Addr2,RMD1000,needComma, RMDAmount, x, y, z, a, NameFirst, NameLast, Addr1_2, Addr2_2,Addr3_2, Addr4_2, Addr5_2,City_2,State_2,Zip_2") wrdDataDoc = oWord.Documents.Open(thisDocName) For iCount = 1 To 1 wrdDataDoc.Tables(1).Rows.Add() Next (iCount) If CurrentFields(fldType.rmd1000) = "rmd1000" Then MsgBox("is the file on the network complete?") Else End If If CurrentFields(fldType.rmd1000) = Nothing Then Else CurrentFields(fldType.rmd1000Command) = "," End If If CurrentFields(fldType.rmd1000) = "$" Then
CurrentFields(fldType.rmd1000Command) = ""
Else
If Val(Trim(Replace(CurrentFields(fldType.rmdAmount), "$", ""))) < 1000 Then '<---- GLS CurrentFields(fldType.rmd1000Command) = "" End If End If FillRow(wrdDataDoc, 3, CurrentFields(fldType.fname), CurrentFields(fldType.lnam), CurrentFields(fldType.ssn), CurrentFields(fldType.addr01), CurrentFields(fldType.planNo), CurrentFields(fldType.addr02), CurrentFields(fldType.rmd1000), CurrentFields(fldType.rmd1000Command), CurrentFields(fldType.rmdAmount), CurrentFields(fldType.rmdFactor), CurrentFields(fldType.ssn), CurrentFields(fldType.rmdAmount), CurrentFields(fldType.date1), CurrentFields(fldType.nameLast), CurrentFields(fldType.nameFirst), CurrentFields(fldType.addr11), CurrentFields(fldType.addr12), CurrentFields(fldType.addr13), CurrentFields(fldType.addr14), CurrentFields(fldType.addr15), CurrentFields(fldType.city1), CurrentFields(fldType.state1), CurrentFields(fldType.zip1)) wrdDataDoc.Save() wrdDataDoc.SaveAs(thisDocName) wrdDataDoc.Close(False) End Sub ''' &lt;summary&gt; ''' insert blank lines in the document ''' &lt;/summary&gt; ''' &lt;param name="LineNum"&gt;&lt;/param&gt; ''' &lt;remarks&gt;&lt;/remarks&gt; Public Sub InsertLines(ByVal LineNum As Integer) Dim iCount As Integer For iCount = 1 To LineNum oWord.Selection.TypeParagraph() Next (iCount) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub FillRow(ByVal Doc As Word.Document, ByVal Row As Integer, _ ByVal Text1 As String, ByVal Text2 As String, ByVal Text3 As String, _ ByVal Text4 As String, ByVal text5 As String, ByVal text6 As String, _ ByVal text7 As String, ByVal text8 As String, ByVal text9 As String, _ ByVal text10 As String, ByVal text11 As String, ByVal text12 As String, _ ByVal text13 As String, ByVal text14 As String, ByVal text15 As String, _ ByVal text16 As String, ByVal text17 As String, ByVal text18 As String, _ ByVal text19 As String, ByVal text20 As String, ByVal text21 As String, ByVal text22 As String, ByVal text23 As String) ' Insert the data into the specific cell. With Doc.Tables(1) .Cell(Row, 1).Range.InsertAfter(Text1) ' first name .Cell(Row, 2).Range.InsertAfter(Text2) ' last name .Cell(Row, 3).Range.InsertAfter(Text3) ' ssn .Cell(Row, 4).Range.InsertAfter(Text4) ' addr1 .Cell(Row, 5).Range.InsertAfter(text5) ' plan no .Cell(Row, 6).Range.InsertAfter(text6) ' addr2 .Cell(Row, 7).Range.InsertAfter(text7) ' dollars thousands() .Cell(Row, 8).Range.InsertAfter(text8) ' comma or no comma() .Cell(Row, 9).Range.InsertAfter(text9) ' rmd amount less than$1,000
.Cell(Row, 10).Range.InsertAfter(text10)     ' rmd factor
.Cell(Row, 11).Range.InsertAfter(text11)     ' ssn
.Cell(Row, 12).Range.InsertAfter(text12)     ' rmd amount less than 1,000
.Cell(Row, 13).Range.InsertAfter(text13)     'month/day/year
.Cell(Row, 14).Range.InsertAfter(text14)     ' first name
.Cell(Row, 15).Range.InsertAfter(text15)     ' last name
.Cell(Row, 21).Range.InsertAfter(text21)     ' city
.Cell(Row, 22).Range.InsertAfter(text22)     ' state
.Cell(Row, 23).Range.InsertAfter(text23)     ' zip
End With
End Sub

Public Sub read_file(ByVal dt As Date)
Dim currentField As String
Dim curField As String
Dim docName As String
'    Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("U:\rmd\FileForMailMerge.txt")
Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser(strDataFolder & "FileForMailMerge.txt") '<---- GLS
Dim currentRow As String()
Try
For Each currentField In currentRow
whichField = 0
For Each curField In Split(currentField, "@")
Select Case whichField
Case 1 To 13, 17 To 23, 25 To 26, 28
CurrentFields(whichField) = curField                                'date
Case 14
If CurrentFields(fldType.lnam) = "lname" Then                         'last name
Dim lnameField As String
Dim nameKount As Integer
nameKount = 0
For Each lnameField In Split(curField, ",")
nameKount = nameKount + 1
'                                        MsgBox(curField)
If nameKount = 1 Then
CurrentFields(fldType.lnam) = lnameField                   'date
CurrentFields(fldType.nameFirst) = CurrentFields(fldType.lnam)
lname_length = (Trim(CurrentFields(fldType.lnam).Length))
End If
If nameKount = 2 Then
CurrentFields(fldType.fname) = Trim(lnameField)
CurrentFields(fldType.nameLast) = CurrentFields(fldType.fname)                'first name
fname_length = (Trim(CurrentFields(fldType.fname).Length))
End If
Next
End If
If CurrentFields(fldType.fname) = "" Then
CurrentFields(fldType.lnam) = curField                              'lname
CurrentFields(fldType.nameFirst) = CurrentFields(fldType.lnam)
lname_length = (Trim(CurrentFields(fldType.lnam).Length))
End If
Case 15
If CurrentFields(fldType.lnam) = "lname" And CurrentFields(fldType.fname) = "" Then
CurrentFields(fldType.fname) = Trim(curField)                        'fname
CurrentFields(fldType.nameLast) = CurrentFields(fldType.fname)
fname_length = (Trim(CurrentFields(fldType.fname).Length))
Else
whichField = whichField + 1
End If
Case 16
If whichField = 24 Then                                        'CurrentFields(fldType.rmd1000) = curField
'rmd1000
If curField <> "rmd1000" Then
whichField = whichField + 1
CurrentFields(fldType.rmd1000) = ""
Else
CurrentFields(fldType.rmd1000) = curField
End If
End If
Case 27
CurrentFields(fldType.ssn) = Trim(curField)                             'ssn
If CurrentFields(fldType.ssn) = "ssn" Then
Else
CurrentFields(fldType.ssnWorkarea) = CurrentFields(fldType.ssn).Substring(7, 4)
CurrentFields(fldType.ssn) = "xxx-xx-" + CurrentFields(fldType.ssnWorkarea)
End If
Case 19
Else
End If
Case 20
Else
End If
Case 21
If CurrentFields(fldType.city0) = "city" Then
CurrentFields(fldType.city1) = "City_2"
Else
CurrentFields(fldType.city1) = CurrentFields(fldType.city0) + ", "
End If
Case 22
If CurrentFields(fldType.state0) = "state" Then
CurrentFields(fldType.state1) = "State_2"
Else
CurrentFields(fldType.state1) = CurrentFields(fldType.state0) + ""
End If
Case 23
If CurrentFields(fldType.zip0) = "zip" Then
CurrentFields(fldType.zip1) = "Zip_2"
Else
CurrentFields(fldType.zip1) = CurrentFields(fldType.zip0)
End If
Case 29
CurrentFields(fldType.qPlanNo) = curField                       'plan
If CurrentFields(fldType.planNo) = "" Then
CurrentFields(fldType.planNo) = CurrentFields(fldType.qPlanNo)
End If
'   CurrentFields(fldType.ssnWorkarea) = curField                       'full SSN
CurrentFields(fldType.ssnWorkarea) = CurrentFields(fldType.ssn).Substring(7, 4)
CurrentFields(fldType.ssn) = "xxx-xx-" + CurrentFields(fldType.ssnWorkarea)
Case 31, 32
CurrentFields(fldType.participantAge) = curField                       'participant AGE
End Select
whichField = whichField + 1
Next curField
Next currentField
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
End Using

docName = strDataFolder & strBackUpSubFolder & "Merge_bkup_" & Trim(CurrentFields(fldType.ssn)) & "_" & CurrentFields(fldType.planNo) & "_" & dt.ToString("dd_hh_nn_ss") & ".doc" '<----- GLS

CurrentFields(fldType.planNo) = Trim(CurrentFields(fldType.planNo))
spouse_10_yrs_younger(CurrentFields(fldType.participantAge))

FileCopy(strDataFolder & "FileForMailMerge.txt", docName & "_input_file")
End Sub
Sub spouse_10_yrs_younger(ByVal age)
'        Dim rmdFactor(20, 30) As Double
'rmdFactor(1, 1) = 19        rmdFactor(1, 2) = 19        rmdFactor(1, 3) = 19        rmdFactor(1, 4) = 19
'rmdFactor(1, 5) = 19        rmdFactor(1, 6) = 19        rmdFactor(1, 7) = 19        rmdFactor(1, 8) = 19
'rmdFactor(1, 9) = 19        rmdFactor(1, 10) = 19        rmdFactor(1, 11) = 19        rmdFactor(1, 12) = 19
'rmdFactor(1, 13) = 19        rmdFactor(1, 14) = 19        rmdFactor(1, 15) = 19        rmdFactor(1, 16) = 19
'rmdFactor(1, 17) = 19        rmdFactor(1, 18) = 19        rmdFactor(1, 19) = 19        rmdFactor(1, 20) = 19
'rmdFactor(1, 21) = 19        rmdFactor(1, 22) = 19        rmdFactor(1, 23) = 19        rmdFactor(1, 24) = 19
'rmdFactor(1, 25) = 19        rmdFactor(1, 26) = 19        rmdFactor(1, 27) = 19        rmdFactor(1, 28) = 19
'rmdFactor(1, 29) = 19        rmdFactor(1, 30) = 19

'rmdFactor(2, 1) = 19        rmdFactor(2, 2) = 19        rmdFactor(2, 3) = 19        rmdFactor(2, 4) = 19
'rmdFactor(2, 5) = 19        rmdFactor(2, 6) = 19        rmdFactor(2, 7) = 19        rmdFactor(2, 8) = 19
'rmdFactor(2, 9) = 19        rmdFactor(2, 10) = 19        rmdFactor(2, 11) = 19        rmdFactor(2, 12) = 19
'rmdFactor(2, 13) = 19        rmdFactor(2, 14) = 19        rmdFactor(2, 15) = 19        rmdFactor(2, 16) = 19
'rmdFactor(2, 17) = 19        rmdFactor(2, 18) = 19        rmdFactor(2, 19) = 19        rmdFactor(2, 20) = 19
'rmdFactor(2, 21) = 19        rmdFactor(2, 22) = 19        rmdFactor(2, 23) = 19        rmdFactor(2, 24) = 19
'rmdFactor(2, 25) = 19        rmdFactor(2, 26) = 19        rmdFactor(2, 27) = 19        rmdFactor(2, 28) = 19
'rmdFactor(2, 29) = 19        rmdFactor(2, 30) = 19

'rmdFactor(2, 1) = 19        rmdFactor(2, 2) = 19        rmdFactor(2, 3) = 19        rmdFactor(2, 4) = 19
'rmdFactor(2, 5) = 19        rmdFactor(2, 6) = 19        rmdFactor(2, 7) = 19        rmdFactor(2, 8) = 19
'rmdFactor(2, 9) = 19        rmdFactor(2, 10) = 19        rmdFactor(2, 11) = 19        rmdFactor(2, 12) = 19
'rmdFactor(2, 13) = 19        rmdFactor(2, 14) = 19        rmdFactor(2, 15) = 19        rmdFactor(2, 16) = 19
'rmdFactor(2, 17) = 19        rmdFactor(2, 18) = 19        rmdFactor(2, 19) = 19        rmdFactor(2, 20) = 19
'rmdFactor(2, 21) = 19        rmdFactor(2, 22) = 19        rmdFactor(2, 23) = 19        rmdFactor(2, 24) = 19
'rmdFactor(2, 25) = 19        rmdFactor(2, 26) = 19        rmdFactor(2, 27) = 19        rmdFactor(2, 28) = 19
'rmdFactor(2, 29) = 19        rmdFactor(2, 30) = 19

'        Dim x As ArrayList
'Select Case age
'    Case 70.0        '    Case 71.0        '    Case 72.0        '    Case 73.0        '    Case 74.0
'    Case 75.0, 75.5
'    Case 75.0, 75.08, 75.12, 75.25, 75.33, 75.41, 75.5, 75.58, 75.64, 75.72, 75.8, 75.88, 75.96
'    Case 76.0, 76.08, 76.12, 76.25, 76.33, 76.41, 76.5, 76.58, 76.64, 76.72, 76.8, 76.88, 76.96
'    Case 77.0, 77.08, 77.12, 77.25, 77.33, 77.41, 77.5, 77.58, 77.64, 77.72, 77.8, 77.88, 77.96
'    Case 78.0, 78.08, 78.12, 78.25, 78.33, 78.41, 78.5, 78.58, 78.64, 78.72, 78.8, 78.88, 78.96
'    Case 79.0, 79.08, 79.12, 79.25, 79.33, 79.41, 79.5, 79.58, 79.64, 79.72, 79.8, 79.88, 79.96
'    Case 80.0, 80.08, 80.12, 80.25, 80.33, 80.41, 80.5, 80.58, 80.64, 80.72, 80.8, 80.88, 80.96
'    Case 77.0, 77.08, 77.12, 77.25, 77.33, 77.41, 77.5, 77.58, 77.64, 77.72, 77.8, 77.88, 77.96
'    Case 78.0, 78.08, 78.12, 78.25, 78.33, 78.41, 78.5, 78.58, 78.64, 78.72, 78.8, 78.88, 78.96
'Case 77.0  Case 78.0 Case 79.0 Case 80.0 Case 81.0 Case 82.0 Case 83.0 Case 84.0 Case 85.0 Case 86.0 Case 87.0
'Case 88.0 Case 89.0 Case 90.0 Case 91.0 Case 92.0 Case 93.0
'End Select

'    Select [ Case ] testexpression
'[ Case expressionlist
'    [ statements ] ]
'[ Case Else
'    [ elsestatements ] ]
'    End Select
'Dim number As Integer = 8
'Select Case number
'    Case 1 To 5
'        Debug.WriteLine("Between 1 and 5, inclusive")
'        ' The following is the only Case clause that evaluates to True.
'    Case 6, 7, 8
'        Debug.WriteLine("Between 6 and 8, inclusive")
'    Case 9 To 10
'        Debug.WriteLine("Equal to 9 or 10")
'    Case Else
'        Debug.WriteLine("Not between 1 and 10, inclusive")
'End Select
'Select Case CurrentFields(fldType.rmdFactor)
'    Case 12.0
'    Case 22.0
'    Case 22.9
'    Case 23.8
'    Case 24.7

'    Case 25.6
'    Case 26.5
'End Select
'If CurrentFields(fldType.rmdFactor) = "" Then
'End If
'        If
'70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80:

'40:  44.0  44.0  43.9  43.9  43.9  43.8  43.8  43.8  43.8  43.8  43.7
'41:  43.1  43.0  43.0  43.0  42.9  42.9  42.9  42.9  42.8  42.8  42.8
'42:  42.2  42.1  42.1  42.0  42.0  42.0  41.9  41.9  41.9  41.9  41.8
'43:  41.3  41.2  41.1  41.1  41.1  41.0  41.0  41.0  40.9  40.9  40.9
'44:  40.3  40.3  40.2  40.2  40.1  40.1  40.1  40.0  40.0  40.0  40.0
'45:  39.4  39.4  39.3  39.3  39.2  39.2  39.1  39.1  39.1  39.1  39.0
'46:  38.6  38.5  38.4  38.4  38.3  38.3  38.2  38.2  38.2  38.1  38.1
'47:  37.7  37.6  37.5  37.5  37.4  37.4  37.3  37.3  37.2  37.2  37.2
'48:  36.8  36.7  36.6  36.6  36.5  36.5  36.4  36.4  36.3  36.3  36.3
'49:  35.9  35.9  35.8  35.7  35.6  35.6  35.5  35.5  35.4  35.4  35.4
'50:  35.1  35.0  34.9  34.8  34.8  34.7  34.6  34.6  34.5  34.5  34.5
'51:  34.3  34.2  34.1  34.0  33.9  33.8  33.8  33.7  33.6  33.6  33.6
'52:  33.4  33.3  33.2  33.1  33.0  33.0  32.9  32.8  32.8  32.7  32.7
'53:  32.6  32.5  32.4  32.3  32.2  32.1  32.0  32.0  31.9  31.8  31.8
'54:  31.8  31.7  31.6  31.5  31.4  31.3  31.2  31.1  31.0  31.0  30.9
'55:  31.1  30.9  30.8  30.6  30.5  30.4  30.3  30.3  30.2  30.1  30.1
'56:  30.3  30.1  30.0  29.8  29.7  29.6  29.5  29.4  29.3  29.3  29.2
'57:  29.5  29.4  29.2  29.1  28.9  28.8  28.7  28.6  28.5  28.4  28.4
'58:  28.8  28.6  28.4  28.3  28.1  28.0  27.9  27.8  27.7  27.6  27.5
'59:  28.1  27.9  27.7  27.5  27.4  27.2  27.1  27.0  26.9  26.8  26.7
'60:  27.4  27.2  27.0  26.8  26.6  26.5  26.3  26.2  26.1  26.0  25.9
'61:  26.7  26.5  26.3  26.1  25.9  25.7  25.6  25.4  25.3  25.2  25.1
'62:  26.1  25.8  25.6  25.4  25.2  25.0  24.8  24.7  24.6  24.4  24.3
'63:  25.4  25.2  24.9  24.7  24.5  24.3  24.1  23.9  23.8  23.7  23.6
'64:  24.8  24.5  24.3  24.0  23.8  23.6  23.4  23.2  23.1  22.9  22.8
'65:  24.3  23.9  23.7  23.4  23.1  22.9  22.7  22.5  22.4  22.2  22.1
'66:  23.7  23.4  23.1  22.8  22.5  22.3  22.0  21.8  21.7  21.5  21.3
'67:  23.2  22.8  22.5  22.2  21.9  21.6  21.4  21.2  21.0  20.8  20.6
'68:  22.7  22.3  22.0  21.6  21.3  21.0  20.8  20.6  20.3  20.1  20.0
'69:  22.2  21.8  21.4  21.1  20.8  20.5  20.2  19.9  19.7  19.5  19.3
'70:  21.8  21.3  20.9  20.6  20.2  19.9  19.6  19.4  19.1  18.9  18.7

'Retirement Account Owner's Age (80 - 90)
'80:81:82:83:84:85:86:87:88:89:90:
'50: 34.5 34.4 34.4 34.4 34.3 34.3 34.3 34.3 34.3 34.3  34.2
'51: 33.6 33.5 33.5 33.5 33.4 33.4 33.4 33.4 33.4 33.3  33.3
'52: 32.7 32.6 32.6 32.6 32.5 32.5 32.5 32.5 32.5 32.4  32.4
'53: 31.8 31.8 31.7 31.7 31.7 31.6 31.6 31.6 31.6 31.5  31.5
'54: 30.9 30.9 30.8 30.8 30.8 30.7 30.7 30.7 30.7 30.7  30.6
'55: 30.1 30.0 30.0 29.9 29.9 29.9 29.8 29.8 29.8 29.8  29.8
'56: 29.2 29.2 29.1 29.1 29.0 29.0 29.0 28.9 28.9 28.9  28.9
'57: 28.4 28.3 28.3 28.2 28.2 28.1 28.1 28.1 28.0 28.0  28.0
'58: 27.5 27.5 27.4 27.4 27.3 27.3 27.2 27.2 27.2 27.2  27.1
'59: 26.7 26.6 26.6 26.5 26.5 26.4 26.4 26.4 26.3 26.3  26.3
'60: 25.9 25.8 25.8 25.7 25.6 25.6 25.5 25.5 25.5 25.4  25.4
'61: 25.1 25.0 24.9 24.9 24.8 24.8 24.7 24.7 24.6 24.6  24.6
'62: 24.3 24.2 24.1 24.1 24.0 23.9 23.9 23.8 23.8 23.8  23.7
'63: 23.6 23.4 23.4 23.3 23.2 23.1 23.1 23.0 23.0 22.9  22.9
'64: 22.8 22.7 22.6 22.5 22.4 22.3 22.3 22.2 22.2 22.1  22.1
'65: 22.1 21.9 21.8 21.7 21.6 21.6 21.5 21.4 21.4 21.3  21.3
'66: 21.3 21.2 21.1 21.0 20.9 20.8 20.7 20.7 20.6 20.5  20.5
'67: 20.6 20.5 20.4 20.2 20.1 20.1 20.0 19.9 19.8 19.8  19.7
'68: 20.0 19.8 19.7 19.5 19.4 19.3 19.2 19.2 19.1 19.0  19.0
'69: 19.3 19.1 19.0 18.8 18.7 18.6 18.5 18.4 18.3 18.3  18.2
'70: 18.7 18.5 18.3 18.2 18.0 17.9 17.8 17.7 17.6 17.6  17.5
'71: 18.1 17.9 17.7 17.5 17.4 17.3 17.1 17.0 16.9 16.9  16.8
'72: 17.5 17.3 17.1 16.9 16.7 16.6 16.5 16.4 16.3 16.2  16.1
'73: 16.9 16.7 16.5 16.3 16.1 16.0 15.8 15.7 15.6 15.5  15.4
'74: 16.4 16.2 15.9 15.7 15.5 15.4 15.2 15.1 15.0 14.9  14.8
'75: 15.9 15.6 15.4 15.2 15.0 14.8 14.6 14.5 14.4 14.3  14.2
'76: 15.4 15.1 14.9 14.7 14.4 14.3 14.1 13.9 13.8 13.7  13.6
'77: 15.0 14.7 14.4 14.2 13.9 13.7 13.5 13.4 13.2 13.1  13.0
'78: 14.5 14.2 13.9 13.7 13.4 13.2 13.0 12.9 12.7 12.6  12.4
'79: 14.1 13.8 13.5 13.2 13.0 12.8 12.5 12.4 12.2 12.0  11.9
'80: 13.8 13.4 13.1 12.8 12.6 12.3 12.1 11.9 11.7 11.5  11.4

'80:81:82:83:84:85:86:87:88:89:90:
'50: 34.5 34.4 34.4 34.4 34.3 34.3 34.3 34.3 34.3 34.3 34.2
'51: 33.6 33.5 33.5 33.5 33.4 33.4 33.4 33.4 33.4 33.3 33.3
'52: 32.7 32.6 32.6 32.6 32.5 32.5 32.5 32.5 32.5 32.4 32.4
'53: 31.8 31.8 31.7 31.7 31.7 31.6 31.6 31.6 31.6 31.5 31.5
'54: 30.9 30.9 30.8 30.8 30.8 30.7 30.7 30.7 30.7 30.7 30.6
'55: 30.1 30.0 30.0 29.9 29.9 29.9 29.8 29.8 29.8 29.8 29.8
'56: 29.2 29.2 29.1 29.1 29.0 29.0 29.0 28.9 28.9 28.9 28.9
'57: 28.4 28.3 28.3 28.2 28.2 28.1 28.1 28.1 28.0 28.0 28.0
'58: 27.5 27.5 27.4 27.4 27.3 27.3 27.2 27.2 27.2 27.2 27.1
'59: 26.7 26.6 26.6 26.5 26.5 26.4 26.4 26.4 26.3 26.3 26.3
'60: 25.9 25.8 25.8 25.7 25.6 25.6 25.5 25.5 25.5 25.4 25.4
'61: 25.1 25.0 24.9 24.9 24.8 24.8 24.7 24.7 24.6 24.6 24.6
'62: 24.3 24.2 24.1 24.1 24.0 23.9 23.9 23.8 23.8 23.8 23.7
'63: 23.6 23.4 23.4 23.3 23.2 23.1 23.1 23.0 23.0 22.9 22.9
'64: 22.8 22.7 22.6 22.5 22.4 22.3 22.3 22.2 22.2 22.1 22.1
'65: 22.1 21.9 21.8 21.7 21.6 21.6 21.5 21.4 21.4 21.3 21.3
'66: 21.3 21.2 21.1 21.0 20.9 20.8 20.7 20.7 20.6 20.5 20.5
'67: 20.6 20.5 20.4 20.2 20.1 20.1 20.0 19.9 19.8 19.8 19.7
'68: 20.0 19.8 19.7 19.5 19.4 19.3 19.2 19.2 19.1 19.0 19.0
'69: 19.3 19.1 19.0 18.8 18.7 18.6 18.5 18.4 18.3 18.3 18.2
'70: 18.7 18.5 18.3 18.2 18.0 17.9 17.8 17.7 17.6 17.6 17.5
'71: 18.1 17.9 17.7 17.5 17.4 17.3 17.1 17.0 16.9 16.9 16.8
'72: 17.5 17.3 17.1 16.9 16.7 16.6 16.5 16.4 16.3 16.2 16.1
'73: 16.9 16.7 16.5 16.3 16.1 16.0 15.8 15.7 15.6 15.5 15.4
'74: 16.4 16.2 15.9 15.7 15.5 15.4 15.2 15.1 15.0 14.9 14.8
'75: 15.9 15.6 15.4 15.2 15.0 14.8 14.6 14.5 14.4 14.3 14.2
'76: 15.4 15.1 14.9 14.7 14.4 14.3 14.1 13.9 13.8 13.7 13.6
'77: 15.0 14.7 14.4 14.2 13.9 13.7 13.5 13.4 13.2 13.1 13.0
'78: 14.5 14.2 13.9 13.7 13.4 13.2 13.0 12.9 12.7 12.6 12.4
'79: 14.1 13.8 13.5 13.2 13.0 12.8 12.5 12.4 12.2 12.0 11.9
'80: 13.8 13.4 13.1 12.8 12.6 12.3 12.1 11.9 11.7 11.5 11.4
End Sub

Dim rmdFactor(20, 30) As Double
Dim sAttr As String
sAttr = System.Configuration.ConfigurationManager.AppSettings("Spouse10Year")
Dim xxx As String = System.Configuration.ConfigurationManager.AppSettings("Spouse10Year")
Console.WriteLine("The value of Key0: " & sAttr)
Dim sAll As NameValueCollection
sAll = System.Configuration.ConfigurationManager.AppSettings()
Dim fieldSSN As String
Dim fieldPlan As String
Dim fieldDOB As String
Dim s As String

For Each s In sAll.AllKeys
Dim xxxx As New ArrayList
Console.WriteLine("Key: " & s & " Value: " & sAll(s))
Dim spouse_rmd = New spouse()
Dim fieldNo As Integer = 0
For Each spouseField In Split(sAll(s), ",")
fieldNo = fieldNo + 1
If fieldNo = 1 Then
fieldSSN = spouseField
spouse_rmd.sp_ssn = fieldSSN
End If
If fieldNo = 2 Then
fieldPlan = spouseField
spouse_rmd.sp_plan = spouseField
End If
If fieldNo = 3 Then
fieldDOB = spouseField
spouse_rmd.spouseDOB = spouseField
End If
Next
'spouse = New spouse(fieldSSN, fieldPlan, fieldDOB)
'           spouse_rmd = New spouse()
'       Next
Next
'Dim lnameField As String
'Dim nameKount As Integer
'nameKount = 0
'For Each lnameField In Split(curField, ",")
'       xxxxx = xxxx
End Sub
'    Public Class spouse(fieldSSN,fieldPlan,fieldDOB)
Public Class spouse
Friend plan As String
Property sp_plan() As String
Get
Return plan
End Get
Set(ByVal value As String)
plan = value
End Set
End Property
Friend ssn As String
Property sp_ssn() As String
Get
Return ssn
End Get
Set(ByVal value As String)
ssn = value
End Set
End Property
Public spouseDOB As String
Property sp_spouseDOB() As String
Get
Return spouseDOB
End Get
Set(ByVal Value As String)
spouseDOB = Value
End Set
End Property
End Class
End Module


Overall you seem to be creating a document from scratch. You attach a file as a Merge datasource with this line, but you don't actually do  the merge

myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName)

which would be:

myMailMergeDoc.MailMerge.Execute

It wouldn't do anything anyway, because there aren't any Merge fields on the document. Instead you put the data directly onto the document.

For some reason the document has a fixed-width font as if it were typed on a typewriter.  The reason might be because you want to align things vertically. However Word has ways to do that, e.g. tabstops and tables.

Word's mail merge works with a main document, with Merge fields on it.

If you do that you can design and format your document nicely in Word, save it and use the document repeatedly in the future. In Word 2007/2010, click on the Start Mail Merge dropdown button. 'The Step-by-Step Mail Merge Wizard...' item will walk you through the process. However your finished document is already close to what you need, so I suggest that you reformat that, and replace the variable data with Merge Fields. If I have time, I'll have at go myself, but I can't be certain of getting the fields right.

You will still need the bit that converts your data file into a datasource.
0

Author Comment

ID: 36713702
OMG ... this awesome help, I will get this tested ASAP!

Thank you so very much!
0

LVL 76

Expert Comment

ID: 36713744
I think that I have introduced an error in the translation of the fields in your datasource. It was more complicated than I realised; so, time permitting, I am having another look at that bit.
0

Author Comment

ID: 36817495
On this document, on the TWO BOXES, the TOP LINE, on each BOX comes up as different size on Different machines.

I have used commands like below, but still have the problem.
]

Is there another parameter that I can use to control this issue?

Is one suggestion is to have the word template stored with the static
information?

this merge the fields into the word

bTable.Cell(1, 1).SetHeight(8, 2)

bTable.Cell(1, 1).SetHeight(8, 1)

bTable.Cell(1, 1).SetHeight(10, 0)

'      bTable.Cell(1, 1).Height = 10

'bTable.Cell(1, 2).Height = 10

'bTable.Cell(1, 3).Height = 10

bTable.Cell(1, 1).Height = 30

bTable.Cell(1, 2).Height = 30

bTable.Cell(1, 3).Height = 30
0

Author Comment

ID: 36818734
Need to control the parameters to ASSURE that the document is produced exactly the same on all WORD documents, ie I need to control the template.

OR WOULD it be easier to  deploy a mail merge template, read the template and merge the fields.

My experience with that , I get 2 documents.  One document is the template without the  merged data and the second is the document with the merged

Data.  Let me know what you think.


Imports Microsoft.Office.Interop.Word

Imports System.Configuration

Imports System.IO 'Imports System.Configuration.ConfigurationManager 'Imports System.Configuration.ConfigurationErrorsException'Dim wdExtend As Object = Microsoft.Office.Interop.Word.WdUnits.wdExtend

Imports System.Collections.Specialized

Imports Microsoft.Office.Interop                    'Imports Microsoft.Office.Interop.Access

Imports Microsoft.Vbe.Interop 'Imports Microsoft.Vbe.Interop.Forms.dll 'Imports Microsoft.Office.Interop.Word 'Acrobat Reader parameters

Imports System.Net

Imports System.Net.Sockets         'Imports Microsoft.WindowsMediaServices.Interop

Imports System.Runtime.InteropServices

Module Module1

Dim pExportFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF

Dim sExportFilePath As String = ""

Dim paramOpenAfterExport As Boolean = False

Dim paramExportOptimizeFor As WdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint

Dim paramExportRange As WdExportRange = WdExportRange.wdExportAllDocument

Dim paramStartPage As Int32 = 2

Dim paramEndPage As Int32 = 2

Dim paramExportItem As WdExportItem = WdExportItem.wdExportDocumentContent

Dim paramIncludeDocProps As Boolean = True

Dim paramKeepIRM As Boolean = True

Dim paramCreateBookmarks As WdExportCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks

Dim paramDocStructureTags As Boolean = True

Dim paramBitmapMissingFonts As Boolean = True

Dim paramUseISO19005_1 As Boolean = False

Dim wdline As Object = Microsoft.Office.Interop.Word.WdUnits.wdLine

Dim wdCharacter As Object = Microsoft.Office.Interop.Word.WdUnits.wdCharacter

'   Dim wdFieldFormCheckBox As Object = Microsoft.Office.Interop.Word.wdFieldFormCheckBox

Dim sAttrX As String             'for appconfig

Dim lname_length As Integer

Dim fname_length As Integer

Dim currentField1 As String          'date

Dim currentField2 As String          'blank

Dim currentField3 As String          'month

Dim currentField4 As String          'day

Dim currentField5 As String          'year

Dim currentField6 As String          'month

Dim currentField7 As String          'day

Dim currentField8 As String          'year

Dim currentField9 As String          'month

Dim currentField10 As String         'day

Dim currentField11 As String         'year

Dim currentField12 As String         'day

Dim currentField13 As String         'year

Dim currentField14 As String         'lname          'addr_length = Trim(currentField16.Length)

Dim currentField15 As String         'fname          'fname_length = (Trim(currentField15.Length))

Dim currentField21 As String         'city

Dim currentField22 As String         'state

Dim currentField23 As String         'zip

Dim currentField24 As String         'rmd1000

Dim currentField24a As String        ' comman for 1000 rmd amount

Dim currentField25 As String         'rmdamount

Dim currentField26 As String         'rmd factor

Dim currentField27 As String         'ssn

Dim currentField28 As String         'plan no

Dim currentField29 As String         'namefirst

Dim currentField30 As String         'namelast

Dim currentField36 As String         'city

Dim currentField37 As String         'state

Dim currentField38 As String         'zip

Dim currentField39 As String         'ssn work area

Dim currentField40 As String         ' participant age

Dim currentField41 As String         '  ?plan no

Dim args As String()

Dim oDoc As Document = Nothing

Dim thisDocName As String 'Font.Name = "Arial Unicode MS"

Dim oWord As Word.Application

Dim whichField As Integer

Dim xxxxx As ArrayList

''' <summary>

''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''' </summary>

''' <remarks></remarks>

Sub Main()

Dim index As Integer = 0

Dim icmpHeaderBufferIndex As Int32 = 0

Dim hoursDate As String

Dim minsDate As String

Dim secondsDate As String

Dim dayDate As String

Dim testDate As DateTime = Now

hoursDate = Hour(testDate)

minsDate = Minute(testDate)

secondsDate = Second(testDate)

dayDate = Day(testDate)

dayDate = Date.Now.Day.ToString()

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim sDocPath As String = ""

Dim wrdSelection As Word.Selection

wrdSelection = Nothing

oWord = CreateObject("Word.Application")

oWord.Visible = True

oDoc.Select()

wrdSelection = oWord.Selection

wrdSelection.PageSetup.LeftMargin = 92.925

wrdSelection.Font.Name = "Courier"

wrdSelection.Font.Size = "9.0"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim objWord As New Word.Application

Dim objDocument As New Word.Document

'Type a code statement that opens the Word document (insert your own path and file name) directly after those added in Step 4:

'       objDocument = objWord.Documents.Open("C:\myDoc.docx")

objDocument = objWord.Documents.Open("V:\RPD\401k Payments\RMD\RMD Auto Letters\_xxx-xx-7948_260730_28_15_43_35.doc")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim MSWord As New Word.Application

Dim WordDoc As New Word.Document

'        WordDoc = MSWord.Documents.Open("C:\Demo.Doc")

'        WordDoc = MSWord.Documents.Open("V:\RPD\401k Payments\RMD\RMD Auto Letters\_xxx-xx-7948_260730_28_15_43_35.doc")

WordDoc = MSWord.Documents.Open("U:\Backup_RMD_FILES\RMD_merge_letter_XXX-XX-3371_180590_11_20_0_28.doc")

'  If you want the user to see it ...

MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal

MSWord.Visible = True

'  Close it all down

MSWord.Quit()

MSWord = Nothing

'

'V:\RPD\401k Payments\RMD\RMD Auto Letters

'

'

'Read more: How to Open a Word Document in VB Net | eHow.com http://www.ehow.com/how_7273931_open-word-document-vb-net.html#ixzz1ZLh9b1jH

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

oDoc.Styles("Normal").ParagraphFormat.SpaceAfter = 10

'oDoc.Styles("Normal").ParagraphFormat.LineSpacing = 13.8

oDoc.Styles("Normal").ParagraphFormat.LineSpacing = 13.5

oDoc.Styles("Normal").ParagraphFormat.DisableLineHeightGrid = 0

oDoc.Styles("Normal").ParagraphFormat.DisableLineHeightGrid.ToString()

oDoc.Styles("Normal").ParagraphFormat.LineSpacingRule = 0

oDoc.Styles("Normal").ParagraphFormat.LineUnitAfter.ToString()

oDoc.Styles("Normal").ParagraphFormat.LineUnitBefore.ToString()

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

CreateMailMergeDataFile(dayDate, hoursDate, minsDate, secondsDate)

'''''''''''''''''''''        ' Insert merge data.   ''''''''''''''''''''''''''''''''''''''''''''

' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim myImage As String

'myImage = "C:\data\nreca_logo_4.png"

myImage = CurDir() & "\nreca_logo_4.png"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim xxDateString As String                         'used for month, the number

Dim xxxxDateString As String                       'used for year, ie 2011

Dim xxxxxDateString As String                      'used for date, ie September 13, 2011

Dim xxxxxxDateString As String                     'used for month spelled out

xxxxxxDateString = ""

xxDateString = Now.Month

xxxxDateString = CStr(CStr(Now.Year))

If xxDateString = 1 Then

xxxxxxDateString = "January"

End If

If xxDateString = 2 Then

xxxxxxDateString = "February"

End If

If xxDateString = 3 Then

xxxxxxDateString = "March"

End If

If xxDateString = 4 Then

xxxxxxDateString = "April"

End If

If xxDateString = 5 Then

xxxxxxDateString = "May"

End If

If xxDateString = 6 Then

xxxxxxDateString = "June"

End If

If xxDateString = 7 Then

xxxxxxDateString = "July"

End If

If xxDateString = 8 Then

xxxxxxDateString = "August"

End If

If xxDateString = 9 Then

xxxxxxDateString = "September"

End If

If xxDateString = 10 Then

xxxxxxDateString = "October"

End If

If xxDateString = 11 Then

xxxxxxDateString = "November"

End If

If xxDateString = 12 Then

xxxxxxDateString = "December"

End If

xxxxxDateString = xxxxxxDateString + " " + CStr(Now.Day) + ", " + xxxxDateString              'used for date, ie September 13, 2011

Dim xDateLength As Integer

xDateLength = xxxxxDateString.Length()

Dim iii, iiii As Integer

iiii = 62 - xDateLength

For iii = 1 To iiii

wrdSelection.TypeText(" ")

Next iii

wrdSelection.InsertDateTime(DateTimeFormat:="MMMM dd, yyyy", InsertAsField:=False)

wrdSelection.TypeText(" ")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.TypeText(currentField15)                  'first name

wrdSelection.TypeText(" ")

wrdSelection.TypeText(currentField14)                  'last name

wrdSelection.TypeText(" ")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

iii = 0

iiii = 77 - fname_length - lname_length

For iii = 1 To iiii

wrdSelection.TypeText(" ")

Next iii

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.TypeText("SSN: ")

wrdSelection.TypeText(currentField27)                  'xxx-xx-xssn

wrdSelection.TypeText(" ")

' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.TypeText(" ")

iii = 0

For iii = 1 To (81 - addr_length)

wrdSelection.TypeText(" ")

Next iii

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.TypeText("REA #: ")

wrdSelection.TypeText(currentField28)                  'REA or Plan No

wrdSelection.TypeText(" ")

'       InsertLines(2)

InsertLines(1)

wrdSelection.TypeText("Re: Required Minimum Distribution                                                               ")

InsertLines(1)

wrdSelection.TypeText("Dear")

wrdSelection.TypeText(" ")

wrdSelection.TypeText(currentField15)                  'first name

wrdSelection.TypeText(" ")

wrdSelection.TypeText(currentField14)                  'last name

wrdSelection.TypeText(":                                                                        ")

wrdSelection.TypeText(" ")

InsertLines(1)

StrToAdd = "The assets in your retirement plans cannot remain tax-deferred indefinitely.  Once you reach age 70½ and retire from service, the IRS requires you to withdraw at least a minimum each year.  You must take an amount known as a required minimum distribution (RMD) from all of your retirement plans except Roth IRAs.  "

StrToAdd = "Each year, NRECA will calculate your RMD for the 401(k) Pension Plan.  The RMD for a year must be withdrawn by December 31st of that year, either in a lump sum or in installments.  However, if you are taking an RMD for the first time, you may delay withdrawing the RMD until April 1st of the year after you turn age 70½ (or, in some cases, after you retire).  If you delay taking it until the next year, you will have to take two minimum distributions during that calendar year.  This can put you in a higher tax bracket for the year, increasing the tax you owe.  "

InsertLines(1)

StrToAdd = "Since you have attained the age of 70½ this year, an RMD from your 401(k) Pension Plan account will be processed.  The amount of your Required Minimum Distribution is:   "

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.TypeText(currentField24)

currentField25 = Trim(currentField25)

wrdSelection.TypeText(currentField25)                   'rmd amount

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.TypeText(".")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

StrToAdd = "  You have the option of delaying this distribution until April 1st of next year, or you can take it this year.  Please indicate below your preference regarding the RMD by checking one of the boxes below:  "

'       InsertLines(1)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

StrToAdd = " |_|    Delay until April 1st of next Year    |_|    Take RMD this year  "

'       StrToAdd = "_                                            _                                                                  |_|    Delay until April 1st of next Year    |_|    Take RMD this year  "

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

InsertLines(1)

'       InsertLines(1)

"Note: If you do not return this letter with your selection, we will delay this RMD until April 1st of next year. "

InsertLines(1)

'        InsertLines(2)

StrToAdd = "Regardless if you elect to defer this payment or not, 10% federal withholding will be applied to your required minimum distribution unless you check the box below.  "

"                                                                                                                                  "

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

StrToAdd = "  _ " '******************

' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

wrdSelection.Font.Name = "Courier"

StrToAdd = " |_|    I elect not to have federal income tax withheld  "

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

InsertLines(1)

"Please complete the information below if you wish to receive your payment by direct deposit regardless if you defer your payment or not.  You must attach a voided check as verification of your bank information.  "

InsertLines(1)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'        InsertLines(1)

Dim bTable As Word.Table

bTable.Style = "Table Grid"

bTable.Style.GetType()

bTable.Columns.Item(1).AutoFit()

bTable.Cell(1, 1).SetHeight(8, 2)

bTable.Cell(1, 1).SetHeight(8, 1)

bTable.Cell(1, 1).SetHeight(10, 0)

'      bTable.Cell(1, 1).Height = 10

'bTable.Cell(1, 2).Height = 10

'bTable.Cell(1, 3).Height = 10

bTable.Cell(2, 1).Height = 30

bTable.Cell(2, 2).Height = 30

bTable.Cell(2, 3).Height = 30

bTable.Cell(1, 1).Range.Text = "Bank Routing Number"

bTable.Cell(1, 2).Range.Text = "Bank Account Number"

bTable.Cell(1, 3).Range.Text = "Name of your Financial Institution"

With oWord.Selection

.SetRange(bTable.Range.End + 1, bTable.Range.End + 1)

.Collapse(Word.WdCollapseDirection.wdCollapseEnd)

End With

InsertLines(0)

InsertLines(1)

Dim cTable As Word.Table

cTable.Style = "Table Grid"

cTable.Cell(1, 1).Height = 10

cTable.Cell(1, 2).Height = 10

cTable.Cell(1, 3).Height = 10

cTable.Cell(2, 1).Height = 30

cTable.Cell(2, 2).Height = 30

cTable.Cell(2, 3).Height = 30

cTable.Cell(2, 4).Height = 30

cTable.Cell(1, 1).Range.Text = "Mailing Address of the Financial Institution"

cTable.Cell(1, 2).Range.Text = "City"

cTable.Cell(1, 3).Range.Text = "State"

cTable.Cell(1, 4).Range.Text = "Zip"

With oWord.Selection

.SetRange(cTable.Range.End + 1, cTable.Range.End + 1)

.Collapse(Word.WdCollapseDirection.wdCollapseEnd)

End With

InsertLines(1)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

StrToAdd = "Please consult your personal tax advisor to determine which option is right for you. Once you have reached a decision, you should sign this letter and return it to: NRECA RPD Unit, PO Box 6127, Lincoln, NE  68506."

InsertLines(1)

wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft

StrToAdd = "          Name (signature required)                                                 Date "

InsertLines(1)

StrToAdd = "Please feel free to contact the Member Contact Center at 866.673.2299 or contactcenter@nreca.coop and ask to be transferred to the 401(k) Pension Plan Unit.  "

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

InsertLines(2)

StrToAdd = "      P.O. Box 6127 - Lincoln, NE 68506 - tel: 866.673.2299   - www.nreca.coop "

InsertLines(1)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.Font.Name = "Courier"

wrdSelection.Font.Size = "14.0"

wrdSelection.Font.Size = "12.0"

InsertLines(1)

oWord.InchesToPoints(0.02)

oWord.MillimetersToPoints(4)

'        InsertLines(6)

InsertLines(3)

InsertLines(2)

wrdSelection.TypeText(" ")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'wrdSelection.TypeText(Text:=vbCrLf) '  wrdSelection.TypeText(Text:=vbCr) ' wrdSelection.TypeText(Text:="^p")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

StrToAdd = "                                                                                                                                                         "                                     'put 2 spaces in to shove the address 2 spaces to the right

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

For iii = 1 To 9999     '(9999999999999 - 1)

wrdSelection.TypeText(" ")

Next iii

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

wrdSelection.Font.Name = "Wingdings"

wrdSelection.Font.Name = "Courier"

'wrdSelection.TypeText("^p")

'       wrdSelection.TypeText(Text:=vbCrLf)

'        wrdSelection.TypeText(Text:=vbCr)

StrToAdd = ""                                     'put 2 spaces in to shove the address 2 spaces to the right

StrToAdd = "  "                                     'put 2 spaces in to shove the address 2 spaces to the right

StrToAdd = "  "                                     'put 2 spaces in to shove the address 2 spaces to the right

InsertLines(1)

InsertLines(1)

InsertLines(1)

StrToAdd = "- - - - - "

Dim xmargin = wrdSelection.PageSetup.LeftMargin    '    92.95

Dim ymargin = wrdSelection.PageSetup.RightMargin   '    90.00

Dim tmargin = wrdSelection.PageSetup.TopMargin     '    72.00

Dim bmargin = wrdSelection.PageSetup.BottomMargin  '    72.00

wrdSelection.PageSetup.LeftMargin = 55.0

wrdSelection.PageSetup.RightMargin = 40.0

wrdSelection.PageSetup.TopMargin = 27.0

wrdSelection.PageSetup.BottomMargin = 2.0

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim docName As String

'        docName = "U:\Backup_RMD_Files\RMD_merge_" +

'        Trim(currentField27) + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + minsDate + "_" + secondsDate + "." + "doc"

docName = "V:\Shardata\Backup_RMD_Files\RMD_merge_" +

Trim(currentField27) + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + minsDate + "_" + secondsDate + "." + "doc"

'        FileCopy(docName, "V:\RPD\401k Payments\RMD\RMD Auto Letters\x")

'        FileCopy("V:\Shardata\FileForMailMerge.txt", docName + "_input_file")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

With oDoc

paramOpenAfterExport = False

Dim und_score As String

und_score = "_"

pExportFormat = WdExportFormat.wdExportFormatXPS

'sExportFilePath = "U:\Doc\RMD_doc_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc"

'sExportFilePath = "V:\Shardata\Doc\RMD_doc_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc"

'oDoc.ExportAsFixedFormat(sExportFilePath, _

'                 pExportFormat, paramOpenAfterExport, _

'                  paramExportOptimizeFor, paramExportRange, paramStartPage, _

'                  paramEndPage, paramExportItem, paramIncludeDocProps, _

'                 paramKeepIRM, paramCreateBookmarks, _

'                  paramDocStructureTags, paramBitmapMissingFonts, _

'                 paramUseISO19005_1)

oDoc.SaveAs(docName)

'           FileCopy(docName, "V:\RPD\401k Payments\RMD\RMD Auto Letters\x_abc_def")

Dim otherName As String

otherName = "V:\RPD\401k Payments\RMD\RMD Auto Letters\_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc"

FileCopy(docName, otherName)

'           FileCopy(docName, sExportFilePath)

Dim myMailMergeDoc As Document = oWord.Documents.Open(docName)

myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName)

myMailMergeDoc.MailMerge.Application.ActiveDocument.BuiltInDocumentProperties.ToString()

End With

With oDoc

paramOpenAfterExport = False

Dim und_score As String

und_score = "_"

pExportFormat = WdExportFormat.wdExportFormatXPS

'sExportFilePath = "U:\Doc\RMD_doc_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc"

'sExportFilePath = "V:\RPD\401k Payments\RMD\RMD Auto Letters\_" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".docmx"

'sExportFilePath = "V:\RPD\401k Payments\RMD\RMD Auto Letters\__" & Trim(currentField27) & und_score & currentField28 & und_score & dayDate & und_score & hoursDate & und_score & minsDate & und_score & secondsDate & ".doc"

'sExportFilePath = "U:\data\xxxxx.doc"

'oDoc.ExportAsFixedFormat(sExportFilePath, _

'               pExportFormat, paramOpenAfterExport, _

'               paramExportOptimizeFor, paramExportRange, paramStartPage, _

'               paramEndPage, paramExportItem, paramIncludeDocProps, _

'               paramKeepIRM, paramCreateBookmarks, _

'               paramDocStructureTags, paramBitmapMissingFonts, _

'               paramUseISO19005_1)

oDoc.SaveAs(docName)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim myMailMergeDoc As Document = oWord.Documents.Open(docName)

myMailMergeDoc.MailMerge.OpenDataSource(Name:=thisDocName)

myMailMergeDoc.MailMerge.Application.ActiveDocument.BuiltInDocumentProperties.ToString()

Dim xxx As String = myMailMergeDoc.MailMerge.Application.ActiveDocument.ProtectionType  ' = WdProtectionType.wdNoProtection

Dim xxxxx As String = myMailMergeDoc.MailMerge.Application.ActiveDocument.ProtectionType  ' = WdProtectionType.wdNoProtection

End With

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''V:\RPD\401k Payments\RMD\RMD Auto Letters

'Notify user we are done.

MsgBox("Mail Merge Complete.", vbMsgBoxSetForeground)

' Release references.

wrdSelection = Nothing

oDoc = Nothing

End Sub

''' &lt;summary&gt;

''' create the mail merge document with the merge fields

''' &lt;/summary&gt;

''' &lt;remarks&gt;&lt;/remarks&gt;

Public Sub CreateMailMergeDataFile(ByVal dayDate, ByVal hoursDate, ByVal minsDate, ByVal secondsDate)

Dim iCount As Integer

'        thisDocName = "U:\Backup_RMD_Files\Merge_bkp_" + currentField27 + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + _

'        minsDate(+"_" + secondsDate + "." + "doc")

thisDocName = "V:\Shardata\Backup_RMD_Files\Merge_bkp_" + currentField27 + "_" + currentField28 + "_" + dayDate + "_" + hoursDate + "_" + _

minsDate + "_" + secondsDate + "." + "doc"

oDoc.MailMerge.CreateDataSource(Name:=thisDocName, _

For iCount = 1 To 1

Next (iCount)

If currentField24 = "rmd1000" Then

MsgBox("is the file on the network complete?")

Else

End If

If currentField24 = Nothing Then

Else

currentField24a = ","

End If

If currentField24 = "$" Then currentField24a = "" Else If currentField25 < 1000 Then currentField24a = "" End If End If FillRow(wrdDataDoc, 3, currentField15, currentField14, currentField27, currentField16, currentField28, currentField17, currentField24, currentField24a, currentField25, currentField26, currentField27, currentField25, currentField1, currentField30, currentField29, currentField31, currentField32, currentField33, currentField34, currentField35, currentField36, currentField37, currentField38) wrdDataDoc.Save() wrdDataDoc.SaveAs(thisDocName) wrdDataDoc.Close(False) End Sub ''' &lt;summary&gt; ''' insert blank lines in the document ''' &lt;/summary&gt; ''' &lt;param name="LineNum"&gt;&lt;/param&gt; ''' &lt;remarks&gt;&lt;/remarks&gt; Public Sub InsertLines(ByVal LineNum As Integer) Dim iCount As Integer For iCount = 1 To LineNum oWord.Selection.TypeParagraph() oWord.Selection.Paragraphs.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle Next (iCount) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' &lt;/summary&gt;' &lt;param name="Doc"&gt;&lt;/param&gt; '&lt;param name="Row"&gt;&lt;/param&gt; ' &lt;param name="Text1"&gt;&lt;/param&gt; ' &lt;param name="Text2"&gt;&lt;/param&gt; &lt;param name="Text3"&gt;&lt;/param&gt; &lt;param name="Text4"&gt;&lt;/param&gt; &lt;param name="text5"&gt;&lt;/param&gt; ' &lt;param name="text6"&gt;&lt;/param&gt; &lt;param name="text7"&gt;&lt;/param&gt; &lt;param name="text8"&gt;&lt;/param&gt; &lt;param name="text9"&gt;&lt;/param&gt; ' &lt;param name="text10"&gt;&lt;/param&gt; &lt;param name="text11"&gt;&lt;/param&gt; &lt;param name="text12"&gt;&lt;/param&gt; &lt;param name="text13"&gt;&lt;/param&gt; ' &lt;param name="text14"&gt;&lt;/param&gt; &lt;param name="text15"&gt;&lt;/param&gt; &lt;param name="text16"&gt;&lt;/param&gt; ' &lt;param name="text17"&gt;&lt;/param&gt; ' &lt;param name="text18"&gt;&lt;/param&gt; ' &lt;param name="text19"&gt;&lt;/param&gt; ' &lt;param name="text20"&gt;&lt;/param&gt; ' &lt;param name="text21"&gt;&lt;/param&gt; ' &lt;param name="text22"&gt;&lt;/param&gt; ' &lt;param name="text23"&gt;&lt;/param&gt; ' &lt;remarks&gt;&lt;/remarks&gt; Public Sub FillRow(ByVal Doc As Word.Document, ByVal Row As Integer, _ ByVal Text1 As String, ByVal Text2 As String, ByVal Text3 As String, _ ByVal Text4 As String, ByVal text5 As String, ByVal text6 As String, _ ByVal text7 As String, ByVal text8 As String, ByVal text9 As String, _ ByVal text10 As String, ByVal text11 As String, ByVal text12 As String, _ ByVal text13 As String, ByVal text14 As String, ByVal text15 As String, _ ByVal text16 As String, ByVal text17 As String, ByVal text18 As String, _ ByVal text19 As String, ByVal text20 As String, ByVal text21 As String, ByVal text22 As String, ByVal text23 As String) ' Insert the data into the specific cell. With Doc.Tables(1) .Cell(Row, 1).Range.InsertAfter(Text1) ' first name .Cell(Row, 2).Range.InsertAfter(Text2) ' last name .Cell(Row, 3).Range.InsertAfter(Text3) ' ssn .Cell(Row, 4).Range.InsertAfter(Text4) ' addr1 .Cell(Row, 5).Range.InsertAfter(text5) ' plan no .Cell(Row, 6).Range.InsertAfter(text6) ' addr2 .Cell(Row, 7).Range.InsertAfter(text7) ' dollars thousands() .Cell(Row, 8).Range.InsertAfter(text8) ' comma or no comma() .Cell(Row, 9).Range.InsertAfter(text9) ' rmd amount less than$1,000

.Cell(Row, 10).Range.InsertAfter(text10)     ' rmd factor

.Cell(Row, 11).Range.InsertAfter(text11)     ' ssn

.Cell(Row, 12).Range.InsertAfter(text12)     ' rmd amount less than 1,000

.Cell(Row, 13).Range.InsertAfter(text13)     'month/day/year

.Cell(Row, 14).Range.InsertAfter(text14)     ' first name

.Cell(Row, 15).Range.InsertAfter(text15)     ' last name

.Cell(Row, 21).Range.InsertAfter(text21)     ' city

.Cell(Row, 22).Range.InsertAfter(text22)     ' state

.Cell(Row, 23).Range.InsertAfter(text23)     ' zip

End With

End Sub

' &lt;summary&gt;

' read the file created by the VBA in the Omni Station

' &lt;/summary&gt;

' &lt;param name="daydate"&gt;&lt;/param&gt;

' &lt;param name="hoursDate"&gt;&lt;/param&gt;

' &lt;param name="minsDate"&gt;&lt;/param&gt;

' &lt;param name="secondsDate"&gt;&lt;/param&gt;

' &lt;remarks&gt;&lt;/remarks&gt;

'   Public Sub Read_File(ByVal showDate As Date, ByVal daydate As String, ByVal hoursDate As String, ByVal minsDate As String, ByVal secondsDate As String)

Public Sub read_file(ByVal daydate As String, ByVal hoursDate As String, ByVal minsDate As String, ByVal secondsDate As String)

Dim currentField As String

Dim curField As String

Dim docName As String

'    Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("U:\rmd\FileForMailMerge.txt")

Dim currentRow As String()

Try

For Each currentField In currentRow

whichField = 0

For Each curField In Split(currentField, "@")

whichField = whichField + 1

If whichField = 1 Then

currentField1 = curField                                'date

End If

If whichField = 2 Then

currentField2 = curField                                'blank

End If

If whichField = 3 Then

currentField3 = curField                                'month

End If

If whichField = 4 Then

currentField4 = curField                                'day

End If

If whichField = 5 Then

currentField5 = curField                                'year

End If

If whichField = 6 Then

currentField6 = curField                                'month

End If

If whichField = 7 Then

currentField7 = curField                                'day

End If

If whichField = 8 Then

currentField8 = curField                                'year

End If

If whichField = 9 Then

currentField9 = curField                                'month

End If

If whichField = 10 Then

currentField10 = curField                                'day

End If

If whichField = 11 Then

currentField11 = curField                                'year

End If

If whichField = 12 Then

currentField12 = curField                                'day

End If

If whichField = 13 Then

currentField13 = curField                                'year

End If

If whichField = 14 Then

If currentField14 = "lname" Then                         'last name

Dim lnameField As String

Dim nameKount As Integer

nameKount = 0

For Each lnameField In Split(curField, ",")

nameKount = nameKount + 1

'                                        MsgBox(curField)

If nameKount = 1 Then

currentField14 = lnameField                   'date

currentField29 = currentField14

lname_length = (Trim(currentField14.Length))

End If

If nameKount = 2 Then

currentField15 = Trim(lnameField)

currentField30 = currentField15                'first name

fname_length = (Trim(currentField15.Length))

End If

Next

End If

If currentField15 = "" Then

currentField14 = curField                              'lname

currentField29 = currentField14

lname_length = (Trim(currentField14.Length))

End If

End If

If whichField = 15 Then

If currentField14 = "lname" And currentField15 = "" Then

currentField15 = Trim(curField)                        'fname

currentField30 = currentField15

fname_length = (Trim(currentField15.Length))

Else

whichField = whichField + 1

End If

End If

If whichField = 16 Then

End If

If whichField = 17 Then

End If

If whichField = 18 Then

End If

If whichField = 19 Then

End If

If whichField = 20 Then

End If

If whichField = 21 Then

currentField21 = curField                                  'city

End If

If whichField = 22 Then

currentField22 = curField                                  'state

End If

If whichField = 23 Then

currentField23 = curField                                  'zip

End If

'                '

If whichField = 24 Then                                        'currentField24 = curField

'rmd1000

If curField <> "rmd1000" Then

whichField = whichField + 1

currentField24 = ""

Else

currentField24 = curField

End If

End If

If whichField = 25 Then

currentField25 = curField                                   'rmdamount

End If

If whichField = 26 Then

currentField26 = curField                                   'rmd factor

End If

If whichField = 27 Then

currentField27 = Trim(curField)                             'ssn

If currentField27 = "ssn" Then

Else

currentField39 = currentField27.Substring(7, 4)

currentField27 = "xxx-xx-" + currentField39

End If

End If

If whichField = 28 Then

currentField28 = curField                                   'planNo

End If

If whichField = 25 Then

currentField25 = curField                                   'rmd amount

End If

If whichField = 14 Then

If currentField14 = "lname" Then

currentField29 = "NameLast"

Else

currentField29 = currentField14

End If

End If

If whichField = 15 Then

If currentField15 = "fname" Then

currentField30 = "NameFirst"

Else

currentField30 = currentField15

End If

End If

If whichField = 16 Then

Else

currentField31 = currentField16

currentField31 = "  " + currentField31

End If

End If

If whichField = 17 Then

Else

'currentField32 = currentField17                     'take empty spaces out of the address

currentField32 = Replace(currentField17, "  ", " ") 'take empty spaces out of the address

currentField32 = Replace(currentField32, "  ", " ") 'take empty spaces out of the address

currentField32 = "  " + currentField32

'currentField32 = currentField32 + ""

End If

End If

If whichField = 18 Then

Else

currentField33 = currentField18

currentField33 = Replace(currentField18, "  ", " ") 'take empty spaces out of the address

currentField33 = Replace(currentField33, "  ", " ") 'take empty spaces out of the address

End If

End If

If whichField = 19 Then

Else

currentField34 = currentField19

currentField34 = Replace(currentField19, "  ", " ") 'take empty spaces out of the address

currentField34 = Replace(currentField34, "  ", " ") 'take empty spaces out of the address

End If

End If

If whichField = 20 Then

Else

currentField35 = currentField20

End If

End If

If whichField = 21 Then

If currentField21 = "city" Then

currentField36 = "City_2"

Else

currentField36 = currentField21 + ", "

End If

End If

If whichField = 22 Then

If currentField22 = "state" Then

currentField37 = "State_2"

Else

currentField37 = currentField22 + ""

End If

End If

If whichField = 23 Then

If currentField23 = "zip" Then

currentField38 = "Zip_2"

Else

currentField38 = currentField23

End If

End If

If whichField = 29 Then

currentField41 = curField                       'plan

If currentField28 = "" Then

currentField28 = currentField41

End If

'   currentField39 = curField                       'full SSN

currentField39 = currentField27.Substring(7, 4)

currentField27 = "xxx-xx-" + currentField39

End If

If whichField = 30 Then ' currentField30 = 30 Then

'plan no

End If

If whichField = 31 Or whichField = 30 Then ' currentField31 = 31 Then

'ssn

End If

If whichField = 31 Or whichField = 32 Then

currentField40 = curField                       'participant AGE

End If

Next

Next

Catch ex As Microsoft.VisualBasic.

FileIO.MalformedLineException

MsgBox("Line " & ex.Message & "is not valid and will be skipped.")

End Try

End While

End Using

'        docName = "U:\Backup_RMD_Files\Merge_bkup_" + Trim(currentField27) + "_" + currentField28 + "_" + daydate + "_" + hoursDate + "_" + _

'        minsDate(+"_" + secondsDate + "." + "doc")

docName = "V:\Shardata\Backup_RMD_Files\Merge_bkup_" + Trim(currentField27) + "_" + currentField28 + "_" + daydate + "_" + hoursDate + "_" + _

minsDate + "_" + secondsDate + "." + "doc"

currentField28 = Trim(currentField28)

'FileCopy("U:\rmd\FileForMailMerge.txt", docName + "_input_file")

'       FileCopy("V:\Shardata\rmd\FileForMailMerge.txt", docName + "_input_file")

FileCopy("V:\Shardata\FileForMailMerge.txt", docName + "_input_file")

End Sub

End Module

0

LVL 76

Expert Comment

ID: 36890780
OK. I am still working on it. I am finding the logic of the read_file procedure difficult to understand.

I do think that designing a 'template' in Word and using that would be better than trying to create one in code.

I am going to ask an editor to put the code into snippets, so that the question is easier to view.

0

LVL 76

Expert Comment

ID: 36899231
Here is a mail merge main document with some merge fields where the variable text should go.
RMD-main2.docx
0

Author Comment

ID: 36900192
Great I will get this tested and get back with you.

0

LVL 76

Accepted Solution

GrahamSkan earned 500 total points
ID: 36900615
This is just an example. You may want to pretty it up a bit, for example by changing the font.

Your code created a document with fixed-width spacing which is useful it there isn't any other way of aligning text vertically, but Word has many techniques that help with that. If you change the font to Times New Roman, for instance, the right-hand block at the top of the letter still stays where it is because we have used right-aligned tab stops. There is no need to count the characters to produce the correct alignment.

I realise that you are creating a form document that will be printed and then filled in with a pen, so there isn't any point in creating a document that is easily editable in Word.

So, in this version. I have used symbols to replace a couple of your carefully-assembled check-box simulations. A third is left in place for comparison. None of them can readily be ticked via the Word application.

In essence the only code that you now need is to edit your data file into an acceptable Mail merge datasource. But if you want complete automation, you may want to .Execute the mail merge as well.

RMD-main2.docx
0

Author Closing Comment

ID: 36913994
Great job I could not have done this without your assistance!
0

LVL 76

Expert Comment

ID: 36914121
Thanks. Good luck with completing the project.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
###### Suggested Courses
Course of the Month2 days, 12 hours left to enroll