Copy RTF text from Access to word table using VBA -


is there way copy rtf text memo field in access database word document using vba. have code @ moment produces html text (the text includes tags , not formatted).

' query database , sales specified customer set rs = currentdb.openrecordset("select * sales sales.[id] ='" & forms![customers]![id] & "'")  'check see if recordset contains rows     if not (rs.eof , rs.bof)     rs.movefirst     until rs.eof = true      ' create file , add rtf text     set ts = fso.createtextfile("c:\temp\temp.rtf", true)     ts.write rs(3)     ts.close      ' add row     doc.tables(1).rows.add      ' number of added row add data      = doc.tables(1).rows.last.index      ' add sale word table     doc.tables(1).cell(i, 2).range.insertfile "c:\temp\temp.rtf", , false       'move next record. don't ever forget this.     rs.movenext    loop else     msgbox "there not records in recordset." end if  msgbox "finished." &  rs.close set rs = nothing 

is there other way this?

note "rich text" option memo fields not store formatted text rtf. formatted text stored html, why seeing html tags in text.

the following access vba code creates word document contains formatted text , saved .rtf. if you're not committed using rtf code modified save document .doc or .docx.

sub formattedtexttoword()     dim objword object  ' word.application     dim fso object  ' filesystemobject     dim f object  ' textstream     dim myhtml string, tempfilespec string      ' grab formatted text memo field     myhtml = dlookup("comments", "mytable", "id=101")      set fso = createobject("scripting.filesystemobject")  ' new filesystemobject     tempfilespec = fso.getspecialfolder(2) & "\" & fso.gettempname & ".htm"      ' write temporary .htm file     set f = fso.createtextfile(tempfilespec, true)     f.write "<html>" & myhtml & "</html>"     f.close     set f = nothing      set objword = createobject("word.application")  ' new word.application     objword.documents.add     objword.selection.insertfile tempfilespec     fso.deletefile tempfilespec     ' word document contains formatted text      objword.activedocument.saveas2 "c:\users\public\zzztest.rtf", 6  ' 6 = wdformatrtf     objword.quit     set objword = nothing     set fso = nothing end sub 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -