P
patskinny
I have the code below which opens a word template and then populates
the form. Sometimes it works no problem and other times I get a
"runtime error" 429 stating "active X component can't create object".
Anyone have insight into the inconsistency?
thank you!!!
below is the code:
Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim prps As Object
Dim strDate As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim strTemplate As String
Dim strTemplatePath As String
Dim strTemplateNameAndPath As String
Dim doc As Word.Document
Dim strTitle As String
Dim strPrompt As String
Set appWord = GetObject(, "Word.Application")
strTemplatePath = appWord.Options.DefaultFilePath
(wdUserTemplatesPath)
Debug.Print "Template path: " & strTemplatePath
strTemplatePath = "B:\CSITE 3.0\Supporting Source Files\word
templates\"
strLetter = "AdminReport.dot"
strTemplateNameAndPath = strTemplatePath & strLetter
Debug.Print "Template and path: " & strTemplateNameAndPath
Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = "Can't find " & strLetter & " in " _
& strTemplatePath & "; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If
Set docs = appWord.Documents
Set doc = docs.Add(strTemplateNameAndPath)
Set prps = doc.CustomDocumentProperties
With prps
.Item("Score").Value = Nz(Me![AdminScore])
.Item("Port").Value = Nz(Me![PortName])
.Item("EvalMonth").Value = Nz(Me![EvalPeriod])
.Item("Q1").Value = Nz(Me![cboAdmin1])
.Item("Q2").Value = Nz(Me![cboAdmin2])
.Item("Q3").Value = Nz(Me![cboAdmin3])
.Item("Q4").Value = Nz(Me![cboAdmin4])
.Item("Q5").Value = Nz(Me![cboAdmin5])
End With
With appWord
.Visible = True
.Activate
.Selection.WholeStory
.Selection.Fields.Update
.Selection.MoveDown Unit:=wdLine, Count:=1
End With
the form. Sometimes it works no problem and other times I get a
"runtime error" 429 stating "active X component can't create object".
Anyone have insight into the inconsistency?
thank you!!!
below is the code:
Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim prps As Object
Dim strDate As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim strTemplate As String
Dim strTemplatePath As String
Dim strTemplateNameAndPath As String
Dim doc As Word.Document
Dim strTitle As String
Dim strPrompt As String
Set appWord = GetObject(, "Word.Application")
strTemplatePath = appWord.Options.DefaultFilePath
(wdUserTemplatesPath)
Debug.Print "Template path: " & strTemplatePath
strTemplatePath = "B:\CSITE 3.0\Supporting Source Files\word
templates\"
strLetter = "AdminReport.dot"
strTemplateNameAndPath = strTemplatePath & strLetter
Debug.Print "Template and path: " & strTemplateNameAndPath
Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = "Can't find " & strLetter & " in " _
& strTemplatePath & "; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If
Set docs = appWord.Documents
Set doc = docs.Add(strTemplateNameAndPath)
Set prps = doc.CustomDocumentProperties
With prps
.Item("Score").Value = Nz(Me![AdminScore])
.Item("Port").Value = Nz(Me![PortName])
.Item("EvalMonth").Value = Nz(Me![EvalPeriod])
.Item("Q1").Value = Nz(Me![cboAdmin1])
.Item("Q2").Value = Nz(Me![cboAdmin2])
.Item("Q3").Value = Nz(Me![cboAdmin3])
.Item("Q4").Value = Nz(Me![cboAdmin4])
.Item("Q5").Value = Nz(Me![cboAdmin5])
End With
With appWord
.Visible = True
.Activate
.Selection.WholeStory
.Selection.Fields.Update
.Selection.MoveDown Unit:=wdLine, Count:=1
End With