Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making A Word Document Visable from Access

Status
Not open for further replies.

gsdcrazy

Programmer
Sep 2, 2002
31
0
0
US
Sometime in 2003/2004, I created Access/Word/Excel software for my wife's volunteer club. I really am not an Access or VBA programmer, but. . . Don't even remember what version of Windows was active at that time, but the Club managed to keep the same versions on two different laptops until last year. The second laptop finally died. They bought a new laptop and think the software could just be loaded. Most of it is working. Some is not. The Access activates Word Documents. They use to activate and be "visable". The software on this laptop is starting Word, but not making it visable. We are running Access 2016. How can I get the report to become visable when the Access executes this code?

Public Function RenewalReports()
Dim appWordObject As New Word.Application

'open Winword
Set appWordObject = CreateObject("Word.Application")

'open new document based on template (if applicable)
appWordObject.Documents.Add Template:="""C:\catc\membership\Software\RenewalReports.dot"", newtemplate:=false"

'show new doc
appWordObject.Visible = True

End Function

Your help is greatly appreciated.
George
 
Hi,

I'd guess that one of the issues might be that in any Microsoft application like Word, Excel, Power Point etc, the document extensions are four characters like .dotx, .docx, xlsx for documents that contain no macro code.

If a 2016 is opening a document, your best results will be to open a version that need no "compatibility mode." That's NOT a .dot!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
You might try using:
appWordObject.Documents.Add Template:="C:\catc\membership\Software\RenewalReports.dot", Visible:=True

Your existing:
appWordObject.Documents.Add Template:="""C:\catc\membership\Software\RenewalReports.dot"", newtemplate:=false"
probably wouldn't create a new document based on the RenewalReports template, because what you're actually passing as the template name is:
"C:\catc\membership\Software\RenewalReports.dot", newtemplate:=false
In other words, the template name you're passing includes a pair of double quotes, plus ', newtemplate:=false'

You might also try moving:
appWordObject.Visible = True
so that it's immediately after:
Set appWordObject = CreateObject("Word.Application")



Cheers
Paul Edstein
[MS MVP - Word]
 
Since the version of Word may/will change, you may be better off by using Late binding. More information about Early binding vs. Late binding here

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Everyone,

Thanks so much for your quick response.

Sorry, I did not mention that the Word Documents are using VBA Macros. The Macros are working just fine. They are contained in a "dot" Word Template that creates the document (doc) through the Macros.

The "quoting" of the "Add Template" command did not seem to affect anything. Adding the "Visible" command to the "Add Template" did not create a document.

It is currently using "Early Binding". I tried it with "Late Binding", but it did not seem to matter. It is a good idea to look into using "Late Binding" to not tie it to a version of Word (It is using "Microsoft Word 97 - 2003 Template" now). I converted one of the templates to the current version and initiated it using "Late Binding". Worked great. I will work on converting them so they are less depended upon the version; however, at least with this, I had to change the code as it was using "dot" and needed to be "dotm". Probably does not happen often with upgrades, but it has been a long time. Thought this might help with the visability. Did not seem to.

Still looking for how to get the documents to be visable.

Thanks for all the ideas.

George
 
You need a path to the template, so, as Paul pointed, you need an exact path name, otherwise the Template parameter points to nowhere. Do you have somewhere "On Error Rezume Next" statement?
Check path, name and extension of the template.
Try slightly modify and debug your code:

[tt]Dim appWordObject As Word.Application
Dim objWordDoc as Word.Document
Set appWordObject = New Word.Application
appWordObject.Visible = True ' make word visible
Set objWordDoc = appWordObject.Documents.Add Template:="C:\catc\membership\Software\RenewalReports.dot" ' should create document from template
[/tt]
Open "Locals" window. Execute the code line by line and observe, what's going on. If objWordDoc is Nothing, try the above code without Template argument (all Add method arguments are optional and have defaults), you should stay with empty document on the screen and word document object in objWordDoc in Locals.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top