K
kinggi
Hi,
I use the following code to update a graph in MS Word. When it runs you can
see the data being updated, but when it quits the object the changes are lost
and the old data is restored.
However, If i break into code and execute the function line-by-line, the
changes are saved.
Any help would be appreciated.
-Steve
Code:
Public Sub UpdateRFSResponsivenessChart(strPath As String)
'Check if the bookmark exists
If Bookmark_Exists(ActiveDocument, "GRAPH_RFS_RESPONSIVENESSYTD") = False
Then
MsgBox "The bookmark '" & "GRAPH_RFS_RESPONSIVENESSYTD" & "' does not
exist. The RFS Movement Chart was not updated."
Exit Sub
End If
Dim oMSGraphWrapper As Word.InlineShape
Dim oDoc As Word.Document
Dim oMSGraphObject As Object
Dim oDataSheet As Graph.DataSheet
Selection.GoTo What:=wdGoToBookmark, Name:="GRAPH_RFS_RESPONSIVENESSYTD"
Set oDoc = ActiveDocument
Set oMSGraphWrapper = Selection.InlineShapes(1)
oMSGraphWrapper.OLEFormat.Edit
Set oMSGraphObject = oMSGraphWrapper.OLEFormat.Object
Set oDataSheet = oMSGraphObject.Application.DataSheet
With oDataSheet
Dim myDataBase As Database
Dim myActiveRecord As Recordset
Set myDataBase = OpenDatabase(strPath)
Set myActiveRecord =
myDataBase.OpenRecordset("tmpCPR_RFS_ResponsivenessGraph", dbOpenForwardOnly)
Dim intA As Integer, intB As Integer
For intA = 15 To 1 Step -1
.Columns(intA).Delete
Next intA
intA = 1
'Loop through all the records in the table until the end-of-file marker is
reached
.Cells(intA, 1).Value = "Responsiveness"
.Cells(intA, 2).Value = "NumberRFS"
intA = intA + 1
Do Until myActiveRecord.EOF = True
.Cells(intA, 1).Value = (myActiveRecord.Fields("Category").Value)
.Cells(intA, 2).Value = (myActiveRecord.Fields("NumberRFS").Value)
'access the next record
myActiveRecord.MoveNext
intA = intA + 1
Loop
'.Update
'Then close the database
myActiveRecord.Close
myDataBase.Close
.Application.Chart.Refresh
End With
With oMSGraphObject.Application
.Update
.Quit
End With
Selection.GoTo What:=wdGoToBookmark, Name:="GRAPH_RFS_RESPONSIVENESSYTD"
Set oDoc = ActiveDocument
Set oMSGraphWrapper = Selection.InlineShapes(1)
oMSGraphWrapper.OLEFormat.Edit
Set oMSGraphObject = oMSGraphWrapper.OLEFormat.Object
oMSGraphObject.Application.Update
oMSGraphObject.Application.Quit
Set oDataSheet = Nothing
Set oMSGraphWrapper = Nothing
Set oDoc = Nothing
Set oMSGraphObject = Nothing
End Sub
I use the following code to update a graph in MS Word. When it runs you can
see the data being updated, but when it quits the object the changes are lost
and the old data is restored.
However, If i break into code and execute the function line-by-line, the
changes are saved.
Any help would be appreciated.
-Steve
Code:
Public Sub UpdateRFSResponsivenessChart(strPath As String)
'Check if the bookmark exists
If Bookmark_Exists(ActiveDocument, "GRAPH_RFS_RESPONSIVENESSYTD") = False
Then
MsgBox "The bookmark '" & "GRAPH_RFS_RESPONSIVENESSYTD" & "' does not
exist. The RFS Movement Chart was not updated."
Exit Sub
End If
Dim oMSGraphWrapper As Word.InlineShape
Dim oDoc As Word.Document
Dim oMSGraphObject As Object
Dim oDataSheet As Graph.DataSheet
Selection.GoTo What:=wdGoToBookmark, Name:="GRAPH_RFS_RESPONSIVENESSYTD"
Set oDoc = ActiveDocument
Set oMSGraphWrapper = Selection.InlineShapes(1)
oMSGraphWrapper.OLEFormat.Edit
Set oMSGraphObject = oMSGraphWrapper.OLEFormat.Object
Set oDataSheet = oMSGraphObject.Application.DataSheet
With oDataSheet
Dim myDataBase As Database
Dim myActiveRecord As Recordset
Set myDataBase = OpenDatabase(strPath)
Set myActiveRecord =
myDataBase.OpenRecordset("tmpCPR_RFS_ResponsivenessGraph", dbOpenForwardOnly)
Dim intA As Integer, intB As Integer
For intA = 15 To 1 Step -1
.Columns(intA).Delete
Next intA
intA = 1
'Loop through all the records in the table until the end-of-file marker is
reached
.Cells(intA, 1).Value = "Responsiveness"
.Cells(intA, 2).Value = "NumberRFS"
intA = intA + 1
Do Until myActiveRecord.EOF = True
.Cells(intA, 1).Value = (myActiveRecord.Fields("Category").Value)
.Cells(intA, 2).Value = (myActiveRecord.Fields("NumberRFS").Value)
'access the next record
myActiveRecord.MoveNext
intA = intA + 1
Loop
'.Update
'Then close the database
myActiveRecord.Close
myDataBase.Close
.Application.Chart.Refresh
End With
With oMSGraphObject.Application
.Update
.Quit
End With
Selection.GoTo What:=wdGoToBookmark, Name:="GRAPH_RFS_RESPONSIVENESSYTD"
Set oDoc = ActiveDocument
Set oMSGraphWrapper = Selection.InlineShapes(1)
oMSGraphWrapper.OLEFormat.Edit
Set oMSGraphObject = oMSGraphWrapper.OLEFormat.Object
oMSGraphObject.Application.Update
oMSGraphObject.Application.Quit
Set oDataSheet = Nothing
Set oMSGraphWrapper = Nothing
Set oDoc = Nothing
Set oMSGraphObject = Nothing
End Sub