Re: Reading DOCX-files from Access table



Hello Peter,

Thank you very much for the codes. I¡¯ve got the issue reproduced on my
side. Here is my test result:

1. Access 2003 + doc environment
I edited your code accordingly to fit the Access 2003 + doc environment. The
generated doc file is identical to the source file, and can be successfully
opened by Word 2003.

2. Access 2007 + docx environment
The generated docx file cannot be opened by Word 2007. It says ¡°The Office
Open XML file cannot be opened because there are problems with the
contents.¡±. Word 2007 provides options to repair the file. When I click on
¡°OK¡± to do the repair, the docx is opened. In order to find out the
difference between the two, I compare them with Windiff.exe. Windiff reports
the only difference lies in the end of the files (shown in binary). Because
docx is, in fact, zip files (see MSDN article ¡°Introducing the Office
(2007) Open XML File Formats¡±
http://msdn.microsoft.com/en-us/library/aa338205.aspx), I rename the output¡¯s
extension to zip, and extract it with winzip, to my surprise, the file can
be extracted successfully, and if I package it and rename it to docx, the
file will be opened! From this point, I get a workaround that is, as you may
say, far from satisfactory: we can programmatically un-package and package
the output docx with some zip libraries to get the file fixed. Peter, please
give me some time, I¡¯m looking into the reason for the subtle difference,
and looking for a better solution for you.

Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

"Peter Karlstr?m" <HayRoller@xxxxxxxxxxxxxxxx> wrote in message
news:D62E3CE1-F62C-48F0-ADD3-5F896B27BE23@xxxxxxxxxxxxxxxx
Hello Jialiang Ge

Thank you for your quick reply.

I have been trying to fully convert everything, so;
Access 2003 (mdb) has been converted to Access 2007 (accdb)
The Word document have been converted from DOC to DOCX, and the
document opens OK from Windows Explorer.
The code for loading the document into the database is located in a module
in the database itself, and looks like this:
+++++ Start code +++++
Private Sub SaveToDB()
Dim db As Database
Dim rs As Recordset2
Dim bytBLOB() As Byte
Dim strImagePath As String
Dim intNum As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT fldReportfile FROM tblSystem")
If rs.RecordCount > 0 Then
strImagePath = "C:\Temp\Report.docx"
With rs
intNum = FreeFile
Open strImagePath For Binary As #intNum
ReDim bytBLOB(FileLen(strImagePath))
Get #intNum, , bytBLOB
Close #1
.Edit
.Fields(0).AppendChunk bytBLOB
.Update
End With
End If
rs.Close
Set db = Nothing
End Sub
+++++ End code +++++
References in the database is to ADODB version 2.8 and Access 12 Object
library along with some others non database references.

The code to save the document to a file from the database in the VB6 COM
Addin looks like this:
+++++ Start code +++++
BlockSize = 50
cm.CommandText = "SELECT fldReportfile FROM tblSystem"
rs.Open cm, , adOpenDynamic, adLockReadOnly
If Not rs.BOF And Not rs.EOF Then
If rs("fldReportfile").ActualSize > 0 Then
file_name = repPath & "\Office Installationreport.docx"
On Error Resume Next
Kill file_name
On Error GoTo CreateReportError
file_num = FreeFile
Open file_name For Binary As #file_num
file_length = rs("fldReportfile").ActualSize
If file_length > 0 Then
num_blocks = file_length / BlockSize
left_over = file_length Mod BlockSize
For block_num = 1 To num_blocks
bytes() = rs("fldReportfile").GetChunk(BlockSize)
Put #file_num, , bytes()
Next block_num
On Error Resume Next
If left_over > 0 Then
bytes() = rs("fldReportfile").GetChunk(left_over)
Put #file_num, , bytes()
End If
Else
MsgBox "Error loading report. Template is missing in the database",
vbSystemModal + vbOKOnly, App.ProductName & " Ver: " & App.Major & "." &
App.Minor & "." & App.Revision
GoTo CreateReportExit
End If
Close #file_num
DoEvents
End If
End If
rs.Close
+++++ End code +++++
Referenses int the project is to ADODB 2.8, DAO 3.6 and to Word 12 Object
Library along with some others.

The Field2 object is not availible in DAO 3.6 or ADODB 2.8, since the
reading from the table is made outside the Access database.

Hope this will get you a complete picture of the situation.

Best Regards

--
Peter Karlstr?m
Midrange AB
Sweden


""Jialiang Ge [MSFT]"" wrote:

Hello Peter,

What's the Access version where the VB6 COM Add-in runs for the docx
files?

If it is Access 2003, as far as I know, Access 2003 does not support
Office
2007 file types in its field object. Docx is likely to be regarded as doc
file based on my tests, and an error may be popped up when users open the
file.

If it is Access 2007, have you tried the new Field object: Field2?
http://msdn.microsoft.com/en-us/library/bb257445.aspx
Access 2007 should support docx files in a good manner.

Please let me know if there's any other questions or concerns.

Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================




.


Loading