Problem Importing Word Fields to Access

G

Guest

Hello - Based on information I found on this forum in an article titled
"Import Data Directly from Word Forms to Access Tables", I've created a Word
Document with matching fields to an Access 2000 Table, and followed all the
steps outlined in the article. I'm having trouble with the actual opening of
the Word Document for the data extraction. After feeding the name of the
Document to the import procedure I get the following error:-2147417851:
Method 'Open' of object 'documents' failed.

When I go back to the folder containing the document and try to open it I
get a message that the document is locked for editing (by me). Pryor to
running the procedure I've had no problem opening the document. I've placed
various copies of the initial document template into the folder with
different names and run the import procedure with the same results each time.
Can anyone help with this?

Thanks so much.
 
J

John Nurick

Hi Gary,

Presumably the error is being raised by a statement like this (which is
copied from Sean Kavanagh's MSDN article):

Set doc = appWord.Documents.Open(strDocName)

This normally works fine unless (a) strDocName doesn't point to a Word
document or (b) Windows thinks the document is locked (e.g. by another
application, or another instance of Word). The message you get when you
try to open the document from Windows explorer suggests the latter.

Possibly there's a hidden instance of Word in memory (left over from
something you did while developing the code) that has a lock on the
file. Rebooting your computer should fix this; after rebooting but
before launching Word, delete any Word temp files in the folder.

I presume you have set a breakpoint on the Documents.Open line and made
sure you are using the correct filename. If not, do so.
 
G

Guest

Hi John,

It seems to be from temp copies created when I make a test document from the
original template. I don't know why this happens, but presumably once the
testing is done and the completed non-template documents are emailed back and
then saved in the appropriate directory this won't be a problem.

I have another issue that I'm hoping you can or will be willing to help
with. If the person filling in the fields on the Word document leaves one
blank the import is aborted due to the database field not allowing zero
length strings. What code could I add to skip that particular field if it is
null?

Thanks for any help you can provide.
 
J

John Nurick

Either allow zero length strings, or use something like this to replace
them with Nulls:

!FirstName = IIf(Len(doc.FormFields("fldFirstName").Result) > 0, _
doc.FormFields("fldFirstName").Result, Null

If the users aren't meant to leave fields blank, you can put validation
code in the Word document by using the formfields' ability to run a
macro when you exit them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top