Extracting raw binary text data from embedded RTF file

Kronix

Registered User.
Local time
Today, 15:15
Joined
Nov 2, 2017
Messages
102
I've been updating a field in a linked ODBC database which takes raw text (I guess it would be called "binary") data from RTF files. That is, the same as opening an RTF document in Notepad and copying the entire file including formatting tags. So far, I've been creating the RTF file in VBA using a Word object like this:

Code:
fn = "C:\MYPATH\MyTemp.rtf"
wDoc.SaveAs2 FileName:=fn, FileFormat:=6

Then I reopen the RTF using this code I found for reading raw text from a file.

Code:
fileno = FreeFile 'Get first free file number
            
Open fn For Input As #fileno
textData = Input$(LOF(fileno), fileno)
Close #fileno

I then can assign textData to the appropriate table field as raw binary text including the jumbled up formatting tags, and it works that way.

My problem is I am now going to have to save several such RTF files to fields, but saving the RTFs to external files and reading them again is time consuming, not to mention I now want to be able to save what is being created in the Access database.

Simply put what I would like to do is have several fields of type OLE Object Wordpad that I can open in Wordpad from within Access, and, after they are each automatically saved in their fields, read them as pure binary text to export to the ODBC table. The problem is I don't know how to use the above "Input" command (or any similar function) for RTF files embedded in the database, since it appears to only take a path to an external file. Is there a similar function that can take an embedded RTF object as an argument?

Of course I could save the embedded files in new temp RTF files and work with those, but that defeats the purpose and I can't believe it's not possible to directly read the binary text from within the database. It doesn't need to be an OLE type if there is some other way to embed in the database.

How can I read the pure binary text data from an embedded RTF file? I would also prefer to save the OLE embedd as format Wordpad instead of MS Word, since Wordpad RTF files take up less space.
 
I'm fairly sure you cannot run automation code linking Wordpad with Access

If I'm reading this correctly, you should be able to do this using bookmarks in Word but as I haven't done anything like it for over 10 years, I'll leave others to give you a detailed answer

However, you may find useful code at Helen Feddema's website: http://www.helenfeddema.com/Code%20Samples.htm
 
Well I found out that OLE is binary so I would have to convert it to text before I can copy it to my ODBC database.

What I want is to edit the file in Wordpad, not Word, because Wordpad is faster, saves smaller RTF files, and I want to prevent advanced features of Word being used that are not compatible with my ODBC database frontend RTF parser. After it is edited with Wordpad and saved, I don't mind if the VBA is done using a Word object if Wordpad doesn't support this thing called "automation." But how would I set up Access to have the file open in Wordpad, but afterwards coded in Word?

And I have no need for bookmarks here. I just want to edit an embedded RTF file with Wordpad and then dump the file to a field over ODBC as raw text string data (including the RTF formatting markers, as if you opened it in Notepad).

I wonder if Attachments would be better than OLE....
 
I can't advise as I rarely use OLE objects & NEVER use attachment fields.
I would recommend you avoid attachment fields as well as these cause significant database bloat.

Why do you need to EMBED the files at all?
Why not have a field containing the path to the files so you open them from Access using a default file handler or an Access web browser control?
 
The RTF files I am working with are smaller components of larger projects. When they are opened in Wordpad, I want them to automatically save when I close them, and I want them to close when Access closes.

Is there any way to change the program that an OLE Object is opened with? I want OLE RTF files to open in Wordpad for editing, but afterwards I want to use the Word object to export the files so I can read them back using the Input function (since Wordpad doesn't have VBA automation but it is available on the list of new files to create in bound and unbound object frames).

Edit: Also, I want the Wordpad window to stay on top of Access so they can't continue performing actions in Access until they close the editing Wordpad. There are already template RTFs that the user can edit. Having the ability to save other external RTFs for every project is confusing and there is always the possibility that they will save under a different name/location.
 
Last edited:
What I want is to edit the file in Wordpad, not Word

While there are people who use all sorts of gyrations to send keystrokes to an app that they have launched, your problem is (I believe) that there is no Wordpad API to be opened by Access. You can use Word with Access because Word exposes its API library which includes all the objects and methods. Essentially, Word "cooperates" with the Component Object Model (COM) of Office programming.

Wordpad, so far as I know, DOES NOT have the corresponding API. Or at least, I looked on my Win7 system and could not find a .DLL that looked like it belonged to Wordpad. So I went online. I found a few references there. If this is really something you want to pursue, you will find a bunch of references by doing a web search of "Wordpad API."

Among my findings was an MSDN article where someone asked the question: "Is there a Wordpad API" and the answer was "No." But they pointed out that if you were really going to try for that, you could look on the MSDN site for program examples.

Be aware that a CVE (Common Vulnerability and Exposure notice) exists for Wordpad and remote code execution. This means that Windows patches either already exist or will exist to PREVENT program exploitation of Wordpad, and therefore, either you won't be able to do much or you might do something only to have it break when the security wonks get around to it.

If you are not familiar with a CVE notice, I can tell you that they are the first "official" stage of the process that leads vendors for ALL software products to determine whether a patch or new release is required. When I was with the U.S. Navy, we watched for new CVE announcements and if we saw one for anything we used, we knew we were going to be busy for a while (because at our site, we had literally a couple of thousand servers that we might have to patch, depending on the CVE contents.)
 

Users who are viewing this thread

Back
Top Bottom