By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,977 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,977 IT Pros & Developers. It's quick & easy.

Word Templates using Visual Basic Editor

P: 1
I am creating a template in Word 2007 using Visual Basic Editor. I am pulling information from an Access database. I know this is probably a stupid question, but for the life of me I can't figure out how I get my data to start on a new page and keep the formatting from the first page once a new record is encountered. I have attached a copy of my code. Any help will be greatly appreciated!!!

Expand|Select|Wrap|Line Numbers
  1. Public blnCancelled As Boolean 
  2.  
  3. Private Sub btnCancel_Click() 
  4. DCAMacro.blnCancelled = True 
  5. Unload Me 
  6. End Sub 
  7.  
  8. Private Sub btnGetData_Click() 
  9. Dim conn As New ADODB.Connection 
  10. Dim rs As New ADODB.Recordset 
  11. Dim lngConnectionState As Long 
  12. Dim strSQL As String 
  13. Dim Appellant As String 
  14. Dim Appellee As String 
  15. Dim DateMandateReleased As Date 
  16. Dim MandateType As String 
  17.  
  18. '*****Set up the connection to the database***** 
  19. conn.ConnectionString = "Provider=MSDAORA; Data Source=TSD1; " 
  20. 'removed login information 
  21.  
  22. '*****Open the connecton to the database***** 
  23. conn.Open 
  24. Set rs = New ADODB.Recordset 
  25.  
  26. '*****Check the state of the database***** 
  27. lngConnectionState = conn.State 
  28. 'If lngConnectionState = adStateOpen Then 
  29.  
  30. '*****Set the datasource***** 
  31. strSQL = "Select Mandate_Type, Parm1, Agency_Description, CaseNo, Appellant, Appellee, Lt_Cases, Opinion_Date, Chief_Judge, Mandate_Date " & _ 
  32.             "From CMS.V_Macro4mandate " & _ 
  33.             "Where Date_Mandate_Released = '25-April-2006' " 
  34.  
  35. '*****Open the recordset***** 
  36. rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic 
  37.  
  38. '*****Get the data if not end of the record set***** 
  39. rs.MoveFirst 
  40. If Not rs.EOF Then 
  41.     Do Until rs.EOF 
  42. DCAMacro.txtAppellant = rs.Fields("Appellant").Value & " " 
  43. DCAMacro.txtAppellee = rs.Fields("Appellee").Value & " " 
  44. DCAMacro.txtCaseNumber = rs.Fields("CaseNo").Value & " " 
  45. DCAMacro.txtLowerTrib = rs.Fields("LT_Cases").Value & " " 
  46. DCAMacro.txtOpinionDate = rs.Fields("Opinion_Date").Value & " " 
  47.  
  48.  
  49. '*****Determine the type of mandate***** 
  50. 'If rs.Fields("Mandate_Type").Value = "DK09" Then 
  51. 'DCAMacro.txtMandate_Type = "Mandate" 
  52. 'End If 
  53. 'If rs.Fields("Mandate_Type").Value = "MA1" Then 
  54. 'DCAMacro.txtMandate_Type = "Agency Mandate" 
  55. 'End If 
  56. 'If rs.Fields("Mandate_Type").Value = "MA2" Then 
  57. 'DCAMacro.txtMandate_Type = "Circuit Court Mandate" 
  58. 'End If 
  59. 'If rs.Fields("Mandate_Type").Value = "MA3" Then 
  60. 'DCAMacro.txtMandate_Type = "Worker's Compensation Mandate" 
  61. 'End If 
  62.  
  63. 'If rs.Fields("CaseNo").Value = "1D" Then 
  64. 'DCAMacro.txtDistrict = "first district" 
  65. 'End If 
  66.  
  67.  
  68. DCAMacro.Hide 'hide the form so the document can come up 
  69. Set DCAMarco = Nothing 
  70.  
  71. '*****Add the generic text and properties that apply to all***** 
  72.  
  73. '*****formatting for heading***** 
  74. Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle 
  75. Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 
  76. Selection.Font.Size = 38 
  77. Selection.Font.Name = "Times New Roman" 
  78. Selection.Font.Bold = wdToggle 
  79. Selection.TypeText Text:="M A N D A T E" 
  80. Selection.Font.Size = 12 
  81. Selection.TypeParagraph 
  82. Selection.TypeText Text:="From" 
  83. Selection.TypeParagraph 
  84. Selection.Font.Size = 14 
  85. Selection.Font.AllCaps = True 
  86. Selection.TypeText Text:="district court of appeal of florida" 
  87. Selection.TypeParagraph 
  88. Selection.TypeText Text:="first district" 
  89. 'Selection.TypeText Text:=txtDistrict.Value 
  90. Selection.Font.AllCaps = False 
  91. Selection.TypeParagraph 
  92. Selection.TypeParagraph 
  93. Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft 
  94. Selection.Font.Size = 11 
  95. Selection.TypeText Text:="To ~(name), ~(title), ~(agency)" 
  96. Selection.TypeParagraph 
  97. Selection.TypeParagraph 
  98. Selection.TypeText Text:="WHEREAS, in the certain cause filed in this Court styled:" 
  99. Selection.TypeParagraph 
  100. Selection.TypeParagraph 
  101. Selection.Font.AllCaps = True 
  102. Selection.TypeText Text:=txtAppellant.Value 
  103. Selection.Font.AllCaps = False 
  104. Selection.TypeText Text:=vbTab 
  105. Selection.TypeText Text:=vbTab 
  106. Selection.TypeText Text:=vbTab 
  107. Selection.TypeText Text:=vbTab 
  108. Selection.TypeText Text:=vbTab 
  109. Selection.TypeText Text:="Case No : " 
  110. Selection.TypeText Text:=txtCaseNumber.Value 
  111. Selection.TypeParagraph 
  112. Selection.TypeParagraph 
  113. Selection.TypeParagraph 
  114. Selection.TypeText Text:="v." 
  115. Selection.TypeText Text:=vbTab 
  116. Selection.TypeText Text:=vbTab 
  117. Selection.TypeText Text:=vbTab 
  118. Selection.TypeText Text:=vbTab 
  119. Selection.TypeText Text:=vbTab 
  120. Selection.TypeText Text:=vbTab 
  121. Selection.TypeText Text:=vbTab 
  122. Selection.TypeText Text:="Lower Tribunal Case No : " 
  123. Selection.TypeText Text:=txtLowerTrib.Value 
  124. Selection.TypeParagraph 
  125. Selection.TypeParagraph 
  126. Selection.TypeParagraph 
  127. Selection.Font.AllCaps = True 
  128. Selection.TypeText Text:=txtAppellee.Value 
  129. Selection.Font.AllCaps = False 
  130. Selection.TypeParagraph 
  131. Selection.TypeParagraph 
  132. Selection.TypeParagraph 
  133. Selection.TypeText Text:="The attached opinion was issued on " 
  134. Selection.TypeText Text:=rs.Fields("Opinion_Date").Value & " " 
  135. Selection.TypeParagraph 
  136. Selection.TypeText Text:="YOU ARE HEREBY COMMANDED that further proceedings, if required, be had in accordance" 
  137. Selection.TypeParagraph 
  138. Selection.TypeText Text:="with said opinion, the rules of Court, and the laws of the State of Florida." 
  139. Selection.TypeParagraph 
  140. Selection.SelectCurrentTabs 
  141. Selection.Paragraphs.TabIndent (1) 
  142. Selection.TypeText Text:="WITNESS the Honorable " 
  143. Selection.TypeText Text:=rs.Fields("Chief_Judge").Value & " " 
  144. Selection.TypeParagraph 
  145. Selection.SelectCurrentTabs 
  146. Selection.Paragraphs.TabIndent (1) 
  147. Selection.TypeText Text:="of the District Court of Appeal of Florida, First District" 
  148. 'Selection.TypeText Text:=txtDistrict.Value 
  149. Selection.TypeText Text:="," 
  150. Selection.TypeParagraph 
  151. Selection.SelectCurrentTabs 
  152. Selection.Paragraphs.TabIndent (1) 
  153. Selection.TypeText Text:="and the Seal of said Court done at Tallahassee, Florida," 
  154. 'Selection.TypeText Text:=txtCity.Text 
  155. Selection.TypeParagraph 
  156. Selection.SelectCurrentTabs 
  157. Selection.Paragraphs.TabIndent (1) 
  158. Selection.TypeText Text:="on this " 
  159. Selection.TypeText Text:=rs.Fields("Mandate_Date").Value & " " 
  160. Selection.ClearParagraphAllFormatting 
  161.  
  162. rs.MoveNext 
  163.  
  164.     Loop 
  165. End If 
  166.  
  167. MsgBox "Done.", vbOKOnly 
  168.  
  169. ' rs.Close 
  170. ' conn.Close 
  171. ' Set conn = Nothing 
  172. ' Set rs = Nothing 
  173.  
  174. End Sub 
Jan 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: 10
hello dear
plz help me soon yaar

1.> How can i create a macro in msword using visul basic editor and how it saves after saving how this macro call in visual basic6

2.> give me full info for this code its very urgent for my educational project.


plz help me soon
Mar 15 '07 #2

P: 10
hello dear
plz help me soon yaar

1.> How can i create a macro in msword using visul basic editor and how it saves after saving how this macro call in visual basic6

2.> give me full info for this code its very urgent for my educational project.


plz help me soon


replay me on
amitkumar19@gmail.com
Mar 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.