Hi everyone, I have the below code working to build a Word document from Access. It works, but I want to justify/distribute the text in the Do loop. I have not found an way to do it on the WEB or the forum. I figure that the code would be like word.App.selection.distribute = true/false.
Can this be done?
Richard
Can this be done?
Richard
Code:
[FONT=Times New Roman][SIZE=3]Public Sub CreateReport()[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman] Dim curDatabase As dao.database[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Dim tbl As dao.Recordset[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Dim strAns As String 'rjm[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Dim strAns2 As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Set curDatabase = CurrentDb[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Set Recordset = curDatabase.OpenRecordset("LandTable", dbOpenSnapshot)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Dim Owner As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]Owner= FilterOwner[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] If Owner = "" Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] MsgBox "No Owner selected"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Else[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Recordset.Filter = "[Owner] = '" & Owner & "'"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Set Recordset = Recordset.OpenRecordset[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Dim wordApp As Object[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Set wordApp = CreateObject(Class:="Word.Application")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.Visible = True[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.Documents.Add[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.typetext _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "Land Report" & vbNewLine & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "Attached to and made a part of that certain ___________" & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "dated _______, by and between My Company and" & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "______________________" & vbNewLine & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] UCase(Recordset!Owner) & " Owner" & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] UCase(Recordset!County) & " COUNTY, TEXAS" & vbNewLine & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "I" & vbNewLine & vbNewLine & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "My Comany" & vbNewLine & vbNewLine & vbNewLine[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Do Until Recordset.EOF[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Dim INSOFARClause As String 'Only added if Owner Survey is not null[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] If Nz(Recordset![Land Ownership], "") = "" Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] INSOFARClause = ""[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Else[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] INSOFARClause = _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] "INSOFAR AND ONLY INSOFAR as said covers " & Recordset![Land Acres] & " acres, more or less, out of the " & Recordset![Land Ownership] & "." & vbNewLine[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] strAns = IIf(INSOFARClause = "", vbNewLine, "")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] 'Recordset![Lease Name] Recordset![Lessee] & ", as Lessee, covering " & - strAns2 & ", as Lessor, and " & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] strAns2 = "" & Recordset.[Lease Name] & ""[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] 'builds Word document[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.typetext _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Recordset![Instrument] & " dated " & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Format(Recordset![Sale Date]) & ", by and between "[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.Font.Bold = True[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.typetext strAns2[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.Font.Bold = False[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.typetext _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] " as a Lessor and " & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Recordset![Lessee] & ", as Lessee, covering " & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Format(Recordset![Land Acres]) & " acres, more or less, out of the " & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Trim(Recordset![Survey]) & ", " & Recordset![County] & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] " County, Texas, and recorded " & Recordset![Record] & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] " of the Official Public Records of " & Recordset![County] & _[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] " County, Texas. " & strAns[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.Font.Bold = True[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.typetext INSOFARClause & vbNewLine[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] wordApp.selection.Font.Bold = False[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Recordset.MoveNext[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Loop[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3]End Sub[/SIZE][/FONT]