ActiveDocument doesn't exist only when OLE Word Document is opened from an Access form

lauro

Member
Local time
Today, 15:20
Joined
May 18, 2012
Messages
59
Hi,

I'm developing a simple database of Word documents in Access.

WORD
  • Each document stored is based an a MainTemplate.dotm and several MyServiceTemplateXx.dotx with Building Blocks specific to different languages.
  • The document template has various content controls and other objects.
  • In the Document_New and Document_Open of MainTemplate.dotm, I run some checks to see if the document is well formed and doing some initializations.

ACCESS
  • The documents are stored in a table (a field is OLE object, another Full Name of the document).
  • In a form I can launch Word to create a new document.
  • In another form I can run a criteria based research that will show the results in a third form
  • In this last form the user can see the Word document in a BoundObjectFrame. Clicking on it, the document is opend in Word.

I didn't work on the project for several months. Now, back on it, I discovered a strange and not constant behaviour.

IF the file is launched from Word, everything is always fine.
IF the file is launched from Access clicking in the BoundObjectFrame, most of the time my checks are non passed because Word will not find an ActiveDocument.

Every call to the ActiveDocument, also in the first line of the Document_Open routine, will trow the error 4228 "The command is not available because the document is not open" or ".. no document is open" (I get the error in Italian).
I remember that all worked fine in the past (but maybe I'm wrong).
I tried the delay a lot in MainTemplate.dotm Document_Open before the first call of ActiveDocument, with no success.
If in the Access Frame of the result shown, I use a CommandButton instead of lauching my help, to launch via my code the Word Document, every thing is fine.
I really don't know how to catch the problem because the Word file is not open by my code but by an Access.
It seems the problem arise in the Access-Word interOp; some time if I try to debug the word document opened also the Access Mask will crash; if I just end the debug, the Access Mask will not freeze.
Sometime the problem arise even before the Word document is launched by the click, it seems also the correct visualization is not possible, also the full name of the document is not shown.

I know that I should be more specific, but I don't know where to look for.

Thanks, Lauro
 
Last edited:
You probably need to prefix with the name of the Word object in Access.
 
Gasman is correct, though we can't tell from your discussion whether you are doing this. WHENEVER you are dealing with an applications object, the "keywords" for that document (such as ActiveDocument for Word or ActiveSheet for Excel) may need prefixing to show the context in which they are active. For Access, the CurrentDB is the "automatically active" object and Me is the "automatically active" Class object. But Access doesn't know the keywords and objects of the other application, so you have to tell it where to look.
 
Thank you to both The_Doc_Man and Gasman,
but I'm not understanding the suggestion.

I didn't understand what and where prefix.

In Access, it seems that I cannot doing anything: the Word document is shown in a BoundObjectFrame, clicking and opening is a normal Access behavior. Moreover when I use my code to launch the word file everything is fine.

In Word, in my MainTemplate.dotm maybe I could do something. but what.

Thanks again, Lauro
 
When you use code like ActiveDocument in the actual Word app, same for Range in Excel, the app knows what you are referring to.
When referring it from a different app like Access, then you need to qualify the reference with the object name yiu used to create that app instance.
So prefix ActiveDocument with whatever the object name you used for Word in Access.
If you do not have that, then I do not know what to offer. :(
 
OK, there may be a disconnect regarding your environment.

Gasman and I are talking about using Access to open a Word application object. If you do this, then you can use Access VBA to manipulate the Word document, but you have to qualify your actions in VBA context by prefixing the objects with the name of the master application object. If this is not what you are doing, then your description is missing something.
 
Perhaps supply your Access version and check for any Office updates since you last looked at it.
 
Hi all, thanks for the interest shown.
I succeded in recreating the problem in a very simple database on a much smaller scale.

I would be very glad if you could try it and tell what is wrong.

My elements are the following:
  • Word template: in my case named "TestTemplate.dotm", inside the template I have only two routine
    • Private Sub Document_New()
      Debug.Print "New Doc : " & ActiveDocument.FullName
      End Sub
    • Private Sub Document_Open()
      Debug.Print "Open Doc : " & ActiveDocument.FullName
      End Sub
  • Access Database:
    • TblFiles, Table with the following fields:
      • ID: auto number, primary key
      • FullName: short text, requested
      • Doc: OleObject, requested.
    • FrmFiles, Form linked with TbFiles, following controls:
      • ID: textbox and label
      • FullaName: textbox and label
      • Doc: BoundObjectFrame and label
      • CmdAdd: commandButton: to create, save and link new file
      • CmdOpen: commandButton: to show present file
      • I'll put the code for this last two command buttons in the attached files
If I open TblFiles, move the cursor over one of the OLE Object inserted | right click | Linked Document Object | Open or Edit, I'll get the 4248 error.
If
I open FrmFiles, move the cursor over the BoundObjectFrame of one of the files created | right click | Linked Document Object | Open or Edit, I'll get the 4248 error.
If
I click on the command with my code to open the document everything is fine.

What do you think?
Thanks a lot, I'm eager to know your ideas.
Lauro
 

Attachments

Users who are viewing this thread

Back
Top Bottom