eed
06-08-2007, 09:57 AM
Hello, all,
Okay, I have been working for a while with code in MS Access that creates and formats documents in MS Word. Trouble is, all my experience involves the document's variable being instantiated and closed within just one function.
Now I have a procedure that is building a 400+ page Word document with Access data. The original code has become so long that MS Access refuses to even run it. I just get an error message that says "Procedure too long."
So, I am attempting to split the original procedure into several functions where one function calls the next. The part I'm not sure of is how to pass a reference to the document from one function to the next.
Function 1
Dim objWord as Word.Application, docWord as Word.Document
Set objWord = New Word.Application
Set docWord = objWord.Documents.Add("MyTemplate.dot")
' do lots of stuff in here to start manipulating the document
' call the next function and pass [what?] so that it can manipulate the same document
I tried saving the file with a certain name, then passing that name to the next function by using something like objWord.Documents(strFilename), but it just kept saying "Bad file name." I also tried defining the second function as Function2(docWord as Word.document) and then calling it with Call Function2(docWord). That got me a "ByRef type mismatch" error.
I know there is probably a simple way to do this, but I am clueless. I just can't seem to get myself to the solution. I appreciate any insight that the far more experienced folks here can offer.
By the way, I am working with Access and Word 2003 in Windows 2000 Pro. Thanks a million!
~ eed
Okay, I have been working for a while with code in MS Access that creates and formats documents in MS Word. Trouble is, all my experience involves the document's variable being instantiated and closed within just one function.
Now I have a procedure that is building a 400+ page Word document with Access data. The original code has become so long that MS Access refuses to even run it. I just get an error message that says "Procedure too long."
So, I am attempting to split the original procedure into several functions where one function calls the next. The part I'm not sure of is how to pass a reference to the document from one function to the next.
Function 1
Dim objWord as Word.Application, docWord as Word.Document
Set objWord = New Word.Application
Set docWord = objWord.Documents.Add("MyTemplate.dot")
' do lots of stuff in here to start manipulating the document
' call the next function and pass [what?] so that it can manipulate the same document
I tried saving the file with a certain name, then passing that name to the next function by using something like objWord.Documents(strFilename), but it just kept saying "Bad file name." I also tried defining the second function as Function2(docWord as Word.document) and then calling it with Call Function2(docWord). That got me a "ByRef type mismatch" error.
I know there is probably a simple way to do this, but I am clueless. I just can't seem to get myself to the solution. I appreciate any insight that the far more experienced folks here can offer.
By the way, I am working with Access and Word 2003 in Windows 2000 Pro. Thanks a million!
~ eed