I am automating Word from access and then run a procedure in the word template
I would like to do different things if the template is opened manually or automated from Access.
The code works but not both ways. What I would like to do is if the user manually opens the template it will run the code in the autonew. However, if the template is automated from Access I do not want it to run the code in the Autonew. When opening from access the Word application is not visible.
According to MS
The problem is when I automate from Access the word template still assumes it was opened by the user (usercontrol = true).
Here is the code in Access calling the Word app
Here is the code that runs if called from access. Unfortunately this does not run until after the AutoNew
In the word template I have an autonew macro that runs when the template opens. The if check always returns true opened by the user or opened from ACCESS.
Any thoughts? Is there another way to bypass the autonew if automated? Other workarounds?
I would like to do different things if the template is opened manually or automated from Access.
The code works but not both ways. What I would like to do is if the user manually opens the template it will run the code in the autonew. However, if the template is automated from Access I do not want it to run the code in the Autonew. When opening from access the Word application is not visible.
According to MS
MSDN said:Application.usercontrol:
True if the application is visible or if it was created or started by the user.
False if you created or started the application programmatically by using the CreateObject or GetObject functions, and the application is hidden. Read/write Boolean.
The problem is when I automate from Access the word template still assumes it was opened by the user (usercontrol = true).
Here is the code in Access calling the Word app
Code:
Set wdApp = CreateObject(Class:="Word.Application")
wdApp.WindowState = wdWindowStateMaximize
'Open the Document
wdApp.Documents.Add strPath
'wdApp.Documents.Open FileName:=strPath
wdApp.Run "CalledFromAccess", GBL_Start_Date, GBL_End_Date, CurrentProject.Path & "\TaskTrackerShadow.accdb"
wdApp.Visible = True
Here is the code that runs if called from access. Unfortunately this does not run until after the AutoNew
Code:
Public Sub CalledFromAccess(startDate As Date, endDate As Date, path As String)
glblStartDate = startDate
glblEndDate = endDate
strDBpath = path
ControllingRoutine
End Sub
In the word template I have an autonew macro that runs when the template opens. The if check always returns true opened by the user or opened from ACCESS.
Code:
Public Sub AutoNew()
'[b] User control does not work. It is always true [/b]
If Application.UserControl Then
frmSelectRange.Show
MsgBox "Pick your database from the file browser."
strDBpath = fGetFileName()
ControllingRoutine
End If
End Sub
Any thoughts? Is there another way to bypass the autonew if automated? Other workarounds?