Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 03-17-2016, 11:23 PM
macropod's Avatar
macropod macropod is online now Adding tables to Created word document whilst other word document open Help Windows 7 64bit Adding tables to Created word document whilst other word document open Help Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I think you'll find the following does the same as your existing code is intended to, but somewhat more consistently and efficiently:
Code:
Sub but_Unsatisfactory_Click()
Dim objWord As Word.Application, doc As Word.Document
Dim WordHeaderFooter As Word.HeaderFooter
Dim QueryA As DAO.Recordset, QueryB As DAO.Recordset, dbs As DAO.Database
Dim strSQLA As String, strSQLB As String
Dim myrange As Range
Dim DA As String, DAX As String
Dim Variable As String
Dim Trange As Range
If Forms!frm_Assess!lst_Referrals.Column(5) <> "" Then
 
  Set dbs = CurrentDb
  DA = Forms!frm_Assess!txt_DA
  DAX = """" & DA & """"
 
  'Query SQL String for Checks
  strSQLA = "SELECT tbl_DA.DAID, tbl_DA.[DA No], tbl_DAConCheck.CheckTitle, tbl_DAConCheck.CheckOutcome, tbl_DAConCheck.CheckComments, tbl_DAConCheck.ConditionCategory, tbl_DAConCheck.Order " & _
    "FROM tbl_DA INNER JOIN tbl_DAConCheck ON tbl_DA.DAID = tbl_DAConCheck.DAID " & _
    "WHERE (((tbl_DA.[DA No])=" & DAX & ") AND ((tbl_DAConCheck.CheckOutcome)<> ""Invisible"")) " & _
    "ORDER BY tbl_DAConCheck.ConditionCategory, tbl_DAConCheck.Order;"
 
  'Query SQL String for RAI
  strSQLB = "SELECT tbl_DA.DAID, tbl_DA.[DA No], tbl_DAConCheck.RAIOutcome, tbl_DAConCheck.RAITitle, tbl_DAConCheck.RequestAdditionalInformation, tbl_DAConCheck.ConditionCategory, tbl_DAConCheck.Order " & _
    "FROM tbl_DA INNER JOIN tbl_DAConCheck ON tbl_DA.DAID = tbl_DAConCheck.DAID " & _
    "WHERE (((tbl_DA.[DA No]) = " & DAX & ") And ((tbl_DAConCheck.RAIOutcome) = True)) " & _
    "ORDER BY tbl_DAConCheck.ConditionCategory, tbl_DAConCheck.Order;"
 
  'Set Recordsets
  Set QueryA = dbs.OpenRecordset(strSQLA)
  Set QueryB = dbs.OpenRecordset(strSQLB)
 
  'Open Word
  Set objWord = CreateObject("Word.Application")
  With objWord
    .Visible = True
    .ScreenUpdating = False
    Set doc = .Documents.Add
    With doc
 
      'Basic Document Format
      With .Styles(wdStyleNormal)
        .Font.Name = "Arial"
        .Font.Size = 11
        With .ParagraphFormat
          .LineSpacingRule = wdLineSpaceSingle
          .SpaceAfter = 0
          .SpaceBefore = 0
        End With
      End With
 
      'Insert Gray Table
      .Tables.Add Range:=.Range.Characters.Last, NumRows:=1, NumColumns:=1, _
        DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
      With .Tables(1)
        .Style = "Table Grid"
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
        With .Cell(1, 1).Range
          .Shading.BackgroundPatternColor = -603937025
          .InsertAfter "Council Report Summary" & vbCr & _
            "The proposed development application does not comply with the requirements of Council's relevant policies."
          .Paragraphs.First.Range.Style = wdStyleStrong
        End With
      End With
      With .Range
        .InsertAfter vbCr & vbCr & QueryA!ConditionCategory & vbCr & vbCr
        With .Paragraphs.Last.Previous.Previous
          .Range.Style = wdStyleStrong
          .Alignment = wdAlignParagraphCenter
        End With
      End With
      .SaveAs CurrentProject.Path & "\TestDoc.doc"
    End With
    .ScreenUpdating = True
  End With
End If
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
add, tables, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding furigana to a Word document rjribbit Word 0 12-03-2015 09:33 AM
Adding tables to Created word document whilst other word document open Help Inexperienced user having dificulty adding text to document I created. Fixed text moves around. Athalwolf Word 2 02-08-2015 09:08 AM
Adding tables to Created word document whilst other word document open Help Error message opening a document in Word "Word cannot open this file because it is larger than 512 M poonamshedge Word 2 09-11-2014 06:11 AM
Adding tables to Created word document whilst other word document open Help Adding and Moving parts of a document in Word PauledInAction Word 4 07-13-2012 02:38 PM
Adding bullets in a protected Word document Cindylu3 Word 0 10-03-2008 03:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft