View Single Post
 
Old 03-17-2016, 11:23 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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