Creating and saving raw Rich Text source code into a field
I'm using an ERP software that stores Rich Text product descriptions in a single Long Text field. The text is simply the source code of Rich Text files. For example, if I open an RTF file in Notepad and copy all of it into the field, it works.
I want to automate the process (via VBA) of creating a Rich Text block of text (typically several pages long), then pasting the source into the Long Text field in the table that is linked via ODBC in Access.
The text will be created from MS Word Template files with bookmarks, that I will fill in from Access tables via VBA code. Then the text must then be converted to RTF format. And finally the RTF source code must be copied directly into the field.
After creating the template files using MS Word, I want everything to run from the Access program via VBA. So the process I have planned is:
1. Open the template, fill in the bookmarks using the Access data, then save the filled in file. This should be straightforward using the Word.Application object.
2. Open the filled in file, and save it in RTF format. Is this just simply using the SaveAs function and specifying RTF format, and making sure the filename has the RTF extension? NOTE: I know that MS Word RTF files are always bigger than RTF files saved in Wordpad. Is there a Wordpad object I can use in VBA so it saves smaller? Or some other way to save smaller RTF files?
3. Open the RTF format file, and copy the entire source into the Long Text field. I'm guessing I need to read the RTF file as a plain text file in VBA (same as Notepad does) using the Input command.
So does this sound good, or is there a simpler way? Furthermore is the issue of all the temporary files being used (template Word doc, filled in Word doc, RTF file). Is there any way to not have all these files being created? Furthermore, can I store all the templates in Access instead of separately, perhaps with a button to update the template if I change it in the future?
And finally, if I need to store files separately, what is the best way to access template files that are stored in the same folder, but can have different absolute paths since the Access program will used on different computers in different folders.
I'm using an ERP software that stores Rich Text product descriptions in a single Long Text field. The text is simply the source code of Rich Text files. For example, if I open an RTF file in Notepad and copy all of it into the field, it works.
I want to automate the process (via VBA) of creating a Rich Text block of text (typically several pages long), then pasting the source into the Long Text field in the table that is linked via ODBC in Access.
The text will be created from MS Word Template files with bookmarks, that I will fill in from Access tables via VBA code. Then the text must then be converted to RTF format. And finally the RTF source code must be copied directly into the field.
After creating the template files using MS Word, I want everything to run from the Access program via VBA. So the process I have planned is:
1. Open the template, fill in the bookmarks using the Access data, then save the filled in file. This should be straightforward using the Word.Application object.
2. Open the filled in file, and save it in RTF format. Is this just simply using the SaveAs function and specifying RTF format, and making sure the filename has the RTF extension? NOTE: I know that MS Word RTF files are always bigger than RTF files saved in Wordpad. Is there a Wordpad object I can use in VBA so it saves smaller? Or some other way to save smaller RTF files?
3. Open the RTF format file, and copy the entire source into the Long Text field. I'm guessing I need to read the RTF file as a plain text file in VBA (same as Notepad does) using the Input command.
So does this sound good, or is there a simpler way? Furthermore is the issue of all the temporary files being used (template Word doc, filled in Word doc, RTF file). Is there any way to not have all these files being created? Furthermore, can I store all the templates in Access instead of separately, perhaps with a button to update the template if I change it in the future?
And finally, if I need to store files separately, what is the best way to access template files that are stored in the same folder, but can have different absolute paths since the Access program will used on different computers in different folders.
Last edited: