I am exporting data from Access (2010) to Word and at the end of the Word document I use the following code segment to place records from a table WarePlantNonCom. The records are placed in Word but I can't find a way to line up the data from the 4 fields under their headings. If a value has extra characters it can push the rest of the data out of line with the previous record or headings. Tried using GetString but it throws an error.
Any help or suggestions appreciated.
tamus121
Any help or suggestions appreciated.
tamus121
Code:
Dim rs As DAO.Recordset
Dim txt As String
Dim new_range As Range
strSql = "SELECT FieldNo, Area, Variety, NonCom FROM WarePlantNonCom WHERE WPID =" & Forms!WarePlantInspLetter!WPID
Set rs = DBEngine(0)(0).OpenRecordset(strSql)
Do Until rs.EOF
txt = txt + " " & rs.Fields("FieldNo") & vbTab & "" & vbTab & "" & vbTab & "" & vbTab & rs.Fields("Area") & vbTab & rs.Fields("Variety") & vbTab & rs.Fields("NonCom") & vbCrLf
rs.MoveNext
Loop
' Close the Recordset
rs.Close
' Make a Range at the end of the Word document
Set new_range = appWord.ActiveDocument.Range
new_range.Collapse wdCollapseEnd
' Insert the text and convert it to a table
new_range.InsertAfter txt
new_range.ConvertToTable Separator:=wdSeparateByParagraphs