T
Tom Ross
Hi
I use the code below to create and populate a table from a adodb recordset.
This is used to produce a printed purchase order.
It works fine except when there is a carriage return, or line feed within
any of the fields in of the recordset. The text after the linefeed comes in
the NEXT Row of the table setting everything else out of sync. It should
come as a second line within that cell. I have tried inserting chr(10),
chr(13), 'vbnewline' in the text and each one of the goes to the next row.
When I add a row to the table manually (with .rows.add ) I can insert text
with embedded returns and the cell in the table expands for mutiline
content.
I hope there is a simple solution of something I can embed in the line. that
will not confuse the createtablefromrecordset function.
OR
Should I build and populate the table manually? In which case I need a
little guidance on how to create the table. I think I can populate it once
it is created. My data has four fields Number, QTY, Description, Price.
Once created, I assume I could add rows, populate cells and set properties.
I suspect the manual approach will be best for me in the long run. I hope
there is some simple code to create the table.
Thanks
Tom
*****************************
Function CreateTableFromRecordset(RngAny As Word.Range, RstAny As
ADODB.Recordset, Optional fincludeFieldnames As Boolean = False) As
Word.Table
Dim objTable As Word.Table
Dim fldAny As ADODB.Field
Dim varData As Variant
Dim strBookmark As String
Dim cField As Long
varData = RstAny.GetString()
With RngAny
.InsertAfter varData
Set objTable = .ConvertToTable()
End With
Set CreateTableFromRecordset = objTable
End Function
I use the code below to create and populate a table from a adodb recordset.
This is used to produce a printed purchase order.
It works fine except when there is a carriage return, or line feed within
any of the fields in of the recordset. The text after the linefeed comes in
the NEXT Row of the table setting everything else out of sync. It should
come as a second line within that cell. I have tried inserting chr(10),
chr(13), 'vbnewline' in the text and each one of the goes to the next row.
When I add a row to the table manually (with .rows.add ) I can insert text
with embedded returns and the cell in the table expands for mutiline
content.
I hope there is a simple solution of something I can embed in the line. that
will not confuse the createtablefromrecordset function.
OR
Should I build and populate the table manually? In which case I need a
little guidance on how to create the table. I think I can populate it once
it is created. My data has four fields Number, QTY, Description, Price.
Once created, I assume I could add rows, populate cells and set properties.
I suspect the manual approach will be best for me in the long run. I hope
there is some simple code to create the table.
Thanks
Tom
*****************************
Function CreateTableFromRecordset(RngAny As Word.Range, RstAny As
ADODB.Recordset, Optional fincludeFieldnames As Boolean = False) As
Word.Table
Dim objTable As Word.Table
Dim fldAny As ADODB.Field
Dim varData As Variant
Dim strBookmark As String
Dim cField As Long
varData = RstAny.GetString()
With RngAny
.InsertAfter varData
Set objTable = .ConvertToTable()
End With
Set CreateTableFromRecordset = objTable
End Function