How to format inserted text?
Hi All
I have a Word application that enables me to get data from a database and insert them into certain fields of the Word table. However the inserted text should be formatted as separate lines one line after the other, not
continuously. Could anyone help me on this? Thanks in advance.
Claire
Re: How to format inserted text?
Post your code, but the logic would be to use a vbNewline or vbCrLf (they are the same actually) to create a line break and
position the next text on the next line.
Re: How to format inserted text?
Hi Robdog888
Here is my code:
VB Code:
sqlstring="Select Description from employee Where CompanyName= " & cname & ""
Set rstEmp=dbs.OpenRecordset(sqlstring)
Do While Not rstEmp.EOF
If IsNull(rstEmp.Fields("Description").Value=False then
Description=rstEmp.Fields("Description").Value
else
Description=""
end if
for num=1 to maxnum
with myTable
.cell(num,1).Range.InsertAfter(Description)
End With
Next num
rstEmp.MoveNext
Loop
I want to add code right after the line:
VB Code:
.cell(num,1).Range.InsertAfter(Description)
that enable the next line not continuous, but start a new line.
Thanks in advance
Claire
[Resolved] Re: How to format inserted text?
Hi robdog888
After I posted my code, I tried add vbnewline into the line:
VB Code:
.cell(num,1).Range.InsertAfter(Description & vbnewline)
it works perfectly, thanks a lot. I spent quite long hours to try to figure out.
Cheers
Claire
Re: How to format inserted text?
Sorry for the delay in getting back to you.
Good job :thumb: and Thanks :)