Word Templates using Visual Basic Editor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trezraven
    New Member
    • Jan 2007
    • 1

    Word Templates using Visual Basic Editor

    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!!!

    Code:
    Public blnCancelled As Boolean 
    
    Private Sub btnCancel_Click() 
    DCAMacro.blnCancelled = True 
    Unload Me 
    End Sub 
    
    Private Sub btnGetData_Click() 
    Dim conn As New ADODB.Connection 
    Dim rs As New ADODB.Recordset 
    Dim lngConnectionState As Long 
    Dim strSQL As String 
    Dim Appellant As String 
    Dim Appellee As String 
    Dim DateMandateReleased As Date 
    Dim MandateType As String 
    
    '*****Set up the connection to the database***** 
    conn.ConnectionString = "Provider=MSDAORA; Data Source=TSD1; " 
    'removed login information 
    
    '*****Open the connecton to the database***** 
    conn.Open 
    Set rs = New ADODB.Recordset 
    
    '*****Check the state of the database***** 
    lngConnectionState = conn.State 
    'If lngConnectionState = adStateOpen Then 
    
    '*****Set the datasource***** 
    strSQL = "Select Mandate_Type, Parm1, Agency_Description, CaseNo, Appellant, Appellee, Lt_Cases, Opinion_Date, Chief_Judge, Mandate_Date " & _ 
                "From CMS.V_Macro4mandate " & _ 
                "Where Date_Mandate_Released = '25-April-2006' " 
                 
    '*****Open the recordset***** 
    rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic 
    
    '*****Get the data if not end of the record set***** 
    rs.MoveFirst 
    If Not rs.EOF Then 
        Do Until rs.EOF 
    DCAMacro.txtAppellant = rs.Fields("Appellant").Value & " " 
    DCAMacro.txtAppellee = rs.Fields("Appellee").Value & " " 
    DCAMacro.txtCaseNumber = rs.Fields("CaseNo").Value & " " 
    DCAMacro.txtLowerTrib = rs.Fields("LT_Cases").Value & " " 
    DCAMacro.txtOpinionDate = rs.Fields("Opinion_Date").Value & " " 
    
    
    '*****Determine the type of mandate***** 
    'If rs.Fields("Mandate_Type").Value = "DK09" Then 
    'DCAMacro.txtMandate_Type = "Mandate" 
    'End If 
    ' 
    'If rs.Fields("Mandate_Type").Value = "MA1" Then 
    'DCAMacro.txtMandate_Type = "Agency Mandate" 
    'End If 
    ' 
    'If rs.Fields("Mandate_Type").Value = "MA2" Then 
    'DCAMacro.txtMandate_Type = "Circuit Court Mandate" 
    'End If 
    ' 
    'If rs.Fields("Mandate_Type").Value = "MA3" Then 
    'DCAMacro.txtMandate_Type = "Worker's Compensation Mandate" 
    'End If 
                 
    'If rs.Fields("CaseNo").Value = "1D" Then 
    'DCAMacro.txtDistrict = "first district" 
    'End If 
    
                 
    DCAMacro.Hide 'hide the form so the document can come up 
    Set DCAMarco = Nothing 
    
    '*****Add the generic text and properties that apply to all***** 
    
    '*****formatting for heading***** 
    Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle 
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 
    Selection.Font.Size = 38 
    Selection.Font.Name = "Times New Roman" 
    Selection.Font.Bold = wdToggle 
    Selection.TypeText Text:="M A N D A T E" 
    Selection.Font.Size = 12 
    Selection.TypeParagraph 
    Selection.TypeText Text:="From" 
    Selection.TypeParagraph 
    Selection.Font.Size = 14 
    Selection.Font.AllCaps = True 
    Selection.TypeText Text:="district court of appeal of florida" 
    Selection.TypeParagraph 
    Selection.TypeText Text:="first district" 
    'Selection.TypeText Text:=txtDistrict.Value 
    Selection.Font.AllCaps = False 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft 
    Selection.Font.Size = 11 
    Selection.TypeText Text:="To ~(name), ~(title), ~(agency)" 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.TypeText Text:="WHEREAS, in the certain cause filed in this Court styled:" 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.Font.AllCaps = True 
    Selection.TypeText Text:=txtAppellant.Value 
    Selection.Font.AllCaps = False 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:="Case No : " 
    Selection.TypeText Text:=txtCaseNumber.Value 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.TypeText Text:="v." 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:=vbTab 
    Selection.TypeText Text:="Lower Tribunal Case No : " 
    Selection.TypeText Text:=txtLowerTrib.Value 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.Font.AllCaps = True 
    Selection.TypeText Text:=txtAppellee.Value 
    Selection.Font.AllCaps = False 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.TypeParagraph 
    Selection.TypeText Text:="The attached opinion was issued on " 
    Selection.TypeText Text:=rs.Fields("Opinion_Date").Value & " " 
    Selection.TypeParagraph 
    Selection.TypeText Text:="YOU ARE HEREBY COMMANDED that further proceedings, if required, be had in accordance" 
    Selection.TypeParagraph 
    Selection.TypeText Text:="with said opinion, the rules of Court, and the laws of the State of Florida." 
    Selection.TypeParagraph 
    Selection.SelectCurrentTabs 
    Selection.Paragraphs.TabIndent (1) 
    Selection.TypeText Text:="WITNESS the Honorable " 
    Selection.TypeText Text:=rs.Fields("Chief_Judge").Value & " " 
    Selection.TypeParagraph 
    Selection.SelectCurrentTabs 
    Selection.Paragraphs.TabIndent (1) 
    Selection.TypeText Text:="of the District Court of Appeal of Florida, First District" 
    'Selection.TypeText Text:=txtDistrict.Value 
    Selection.TypeText Text:="," 
    Selection.TypeParagraph 
    Selection.SelectCurrentTabs 
    Selection.Paragraphs.TabIndent (1) 
    Selection.TypeText Text:="and the Seal of said Court done at Tallahassee, Florida," 
    'Selection.TypeText Text:=txtCity.Text 
    Selection.TypeParagraph 
    Selection.SelectCurrentTabs 
    Selection.Paragraphs.TabIndent (1) 
    Selection.TypeText Text:="on this " 
    Selection.TypeText Text:=rs.Fields("Mandate_Date").Value & " " 
    Selection.ClearParagraphAllFormatting 
    
    rs.MoveNext 
    
        Loop 
    End If 
        
    MsgBox "Done.", vbOKOnly 
    
    ' rs.Close 
    ' conn.Close 
    ' Set conn = Nothing 
    ' Set rs = Nothing 
        
    End Sub
  • rinku123
    New Member
    • Mar 2007
    • 10

    #2
    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

    Comment

    • rinku123
      New Member
      • Mar 2007
      • 10

      #3
      Originally posted by rinku123
      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@gma il.com

      Comment

      Working...