B
Beeeehh
Hello,
I am using a Word template to be able to save a report as a new
document.
I have set a button in Access that is calling the template.
Everything is working fine on Access and Word 2002, but when I tried to
Work it on 2003,
I get an error runtime error 5852 requested Object is Not available.
The macro in Word is as follow :
Option Explicit
Public strFileName As String
Private Sub Document_New()
'ActiveDocument.MailMerge.OpenDataSource Name:="JSEA.mdb"
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
RunAfterDocNew
End Sub
Public Sub RunAfterDocNew()
MergeToNewDoc
JSEASaveFile
MoveAllTasksToFirstTable
DeleteExtraPages
CloseWord
End Sub
Public Sub MergeToNewDoc()
'This puts all the records into one document.
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
'ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges'
End Sub
Public Sub JSEASaveFile()
Dim strJSEANum As String
Dim strJSEATitle As String
'Set the file name to the number and title of the JSEA
strJSEATitle = ActiveDocument.Bookmarks("JobName").Range.Text
strJSEANum = ActiveDocument.Bookmarks("JSEANumber").Range.Text
strFileName = strJSEANum & " " & strJSEATitle
'Let User Select a path to save the file
With Dialogs(wdDialogFileSaveAs)
.Name = strFileName
.Show
End With
End Sub
Public Sub MoveAllTasksToFirstTable()
Dim intTotalTables As Integer
Dim iCount As Integer
Dim iiCount As Integer
Dim intTotalSections
intTotalTables = ActiveDocument.Tables.Count
'Now cycle thru all the tables besides the first one
'and pull out the task (which is in the first row) and add it to the
first table
For iCount = 2 To intTotalTables
ActiveDocument.Tables(iCount).Rows(2).Select
Selection.Copy
ActiveDocument.Tables(1).Rows(iCount + 1).Range.Paste
Next iCount
End Sub
Public Sub DeleteExtraPages()
Dim rngExtra As Range
ActiveDocument.Tables(2).Select
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete
End Sub
Public Sub CloseWord()
Dim oWordApp As Word.Application
ActiveDocument.Save
Documents.Close SaveChanges:=wdDoNotSaveChanges
'Word.Application.Quit'
'Set oWordApp = Nothing'
End Sub
If I try to debug it, the first error appear on
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
If I tried to pass it, it stopped on .Destination =
wdSendToNewDocument
and so on.
Does anybody knows what is wrong ?
Hope You can help.
Regards.
I am using a Word template to be able to save a report as a new
document.
I have set a button in Access that is calling the template.
Everything is working fine on Access and Word 2002, but when I tried to
Work it on 2003,
I get an error runtime error 5852 requested Object is Not available.
The macro in Word is as follow :
Option Explicit
Public strFileName As String
Private Sub Document_New()
'ActiveDocument.MailMerge.OpenDataSource Name:="JSEA.mdb"
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
RunAfterDocNew
End Sub
Public Sub RunAfterDocNew()
MergeToNewDoc
JSEASaveFile
MoveAllTasksToFirstTable
DeleteExtraPages
CloseWord
End Sub
Public Sub MergeToNewDoc()
'This puts all the records into one document.
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
'ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges'
End Sub
Public Sub JSEASaveFile()
Dim strJSEANum As String
Dim strJSEATitle As String
'Set the file name to the number and title of the JSEA
strJSEATitle = ActiveDocument.Bookmarks("JobName").Range.Text
strJSEANum = ActiveDocument.Bookmarks("JSEANumber").Range.Text
strFileName = strJSEANum & " " & strJSEATitle
'Let User Select a path to save the file
With Dialogs(wdDialogFileSaveAs)
.Name = strFileName
.Show
End With
End Sub
Public Sub MoveAllTasksToFirstTable()
Dim intTotalTables As Integer
Dim iCount As Integer
Dim iiCount As Integer
Dim intTotalSections
intTotalTables = ActiveDocument.Tables.Count
'Now cycle thru all the tables besides the first one
'and pull out the task (which is in the first row) and add it to the
first table
For iCount = 2 To intTotalTables
ActiveDocument.Tables(iCount).Rows(2).Select
Selection.Copy
ActiveDocument.Tables(1).Rows(iCount + 1).Range.Paste
Next iCount
End Sub
Public Sub DeleteExtraPages()
Dim rngExtra As Range
ActiveDocument.Tables(2).Select
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete
End Sub
Public Sub CloseWord()
Dim oWordApp As Word.Application
ActiveDocument.Save
Documents.Close SaveChanges:=wdDoNotSaveChanges
'Word.Application.Quit'
'Set oWordApp = Nothing'
End Sub
If I try to debug it, the first error appear on
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
If I tried to pass it, it stopped on .Destination =
wdSendToNewDocument
and so on.
Does anybody knows what is wrong ?
Hope You can help.
Regards.