Display/Update Picture Chart Dynamically in Word Using VBA
Hi all,
I am super green working with VBA (asp.net developer) and i have a project to complete where I have to update a Word chart with values obtained from a Stored Procedure (SP).
As my code stands, I have code that reads values from my SP and creates a table within Word. What i would like to do from there is create a chart just underneath the table with the values input from my table so as the values derived from the SP change, the Chart will change accordingly. Here is the code that I used to write out the table (again, I am new to VBA code so I am sure there is a better way of doing this):
Sub FillSelfEval()
Dim lst As Table
Set lst = ActiveDocument.Tables(1)
Dim intnum As Integer
intnum = 2
Dim chgVal As Integer
chgVal = 1
Dim rs As ADODB.Recordset
Dim db As Object
Set db = New ADODB.Connection
db.ConnectionString = "DSN=SelfEval; UID=""; PWD=''"
db.Mode = ADODB.ConnectModeEnum.adModeReadWrite
db.Open
ActiveDocument.Tables(1).Rows.Add
'label the first cell
lst.Cell(3, 1).Range.Text = "SELF"
Do While intnum < 11
Set rs = db.Execute _
("EXEC SelfEval.dbo.spSectionScore '" & par1 & "', '" & par2 & "', '" & par3 & "', '" & chgVal & "'")
'Create new column
If intnum > ActiveDocument.Tables(1).Columns.Count Then
ActiveDocument.Tables(1).Columns(ActiveDocument.Ta bles(1).Columns.Count).Select
With Selection
.Copy
.PasteSpecial
End With
End If
If Not rs.EOF Then
lst.Cell(3, intnum).Range.Text = rs("AverageScore")
Else
lst.Cell(3, intnum).Range.Text = 0
End If
intnum = intnum + 1
chgVal = chgVal + 1
Loop
rs.Close
End Sub
I can copy the values and paste them into the Chart but need a way to perform the actions dynamically. Any help on this is greatly appreciated and please assume I know very little! Thanks in advance!
__________________
SLBIBS
|