I have encountered a problem with some of one of my access databases due to a rollout of security patches and etc at my company. I have an access database that dumps data into a word template. The template contains instructions for filling out the rest of the needed information. I have a button on the word document with caption that says "remove instructions" at that point, I have word try and copy all of the text out of the document with proper formatting into a new word document that has no macros/code behind the scene for a user to fill in their information and save.
Here is the code:
Option Explicit
Dim objword As Object, ObjWordApp As Object, strName As String, aDoc As Document
__________________________________________________ _______________
Public Sub Document_New()
On Error GoTo errorhandler
Set objword = ActiveDocument
objword.MailMerge.OpenDataSource _
Name:="C:\DbWork\LtrRes.accde", _
LinkToSource:=True, _
Connection:="QUERY qryDocument", _
SQLStatement:="Select * from [qryDocument]"
' Execute the mail merge.
objword.MailMerge.Execute
objword.Close (0)
errorhandler:
If Err.Number > 0 Then
MsgBox "Data was not pulled for this template. Please use this blank template to manually fill in fields."
End If
End Sub
__________________________________________________ _______________
Private Sub CommandButton1_Click()
With ActiveDocument.Content.Find
With Selection.Find
.ClearFormatting
.Font.Color = wdColorTeal
.Replacement.ClearFormatting
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll, Forward:=True, _
Wrap:=wdFindContinue
End With
End With
DeleteThis
End Sub
__________________________________________________ ________________
Private Sub DeleteThis()
Dim o As Object
'ActiveDocument.ToggleFormsDesign
For Each o In ActiveDocument.InlineShapes
If o.OLEFormat.Object.Caption = "Remove Instructions" Then
o.Delete
End If
Next
strName = ActiveDocument.Name
CopyDoc (strName)
Documents(strName).Close (0)
End Sub
__________________________________________________ ________________
Public Sub CopyDoc(DocName As String)
Documents(DocName).Range.StartOf Unit:=wdSection, Extend:=wdExtend
Documents(DocName).Range.MoveEnd Unit:=wdSection
Documents(DocName).Select
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub
Basically what happens is it just crashes out and nothing gets copied into the new word document. Any help would be greatly appreciated. Let me know if you need anymore deatils