Hi,

I have copied the code from Mastering Access97 Development by Alison Balters, page 724, as I learn to play with Access and the accessing of other MS applications with code. The code is located bellow. However, i get an error:

Sub or Function not defined at this line


" Source:=Range("A1:B22"), " with the word "Range" blue highlighted. I don't understand why? can somebody help me with this?? Am I missing something??



Public Sub cmdCreateGraph_Click()
On Error GoTo cmdCreateGraph_Err
Dim db As DATABASE
Dim rs As Recordset
Dim fld As Field
Dim objWS As Object
Dim intRowCount As Integer
Dim intColCount As Integer

DoCmd.Hourglass True
Set db = CurrentDb

If CreateRecordset(db, rs, "qrySalesByCountry") Then
If CreateExcelObj() Then
gobjExcel.Workbooks.Add
Set objWS = gobjExcel.ActiveSheet
intRowCount = 1
intColCount = 1
For Each fld In rs.Fields
If fld.Type <> dbLongBinary Then
objWS.Cells(1, intColCount).Value = fld.Name
intColCount = intColCount + 1
End If
Next fld

Do Until rs.EOF
intColCount = 1
intRowCount = intRowCount + 1
For Each fld In rs.Fields
If fld.Type <> dbLongBinary Then
objWS.Cells(intRowCount, intColCount).Value = fld.Name
intColCount = intColCount + 1
End If
Next fld
rs.MoveNext
Loop
gobjExcel.Columns("A:B").SELECT
gobjExcel.Columns("A:B").EntireColumn.AutoFit
gobjExcel.Range("A1").SELECT
gobjExcel.ActiveCell.CurrentRegion.SELECT
gobjExcel.ActiveSheet.ChartObjects.Add(135.75, 14.25, 607.75, 301).SELECT
gobjExcel.ActiveChart.ChartWizard Source:=Range("A1:B22"), _
Gallery:=xlColumn, _
Format:=6, PlotBy:=xlColumns, CategoryLabels:=1, SeriesLabels _
:=1, HasLegend:=1, Title:="Sales By Country Richard", CategoryTitle _
:="", ValueTitle:="", ExtraTitle:=""

gobjExcel.Visible = True
Else
MsgBox "Excel Not Successfully Launched"
End If
Else
MsgBox " Too many Records to send to excel"
End If
DoCmd.Hourglass False

cmdCreateGraph_Exit:
Set db = Nothing
Set rs = Nothing
Set fld = Nothing
Set objWS = Nothing
DoCmd.Hourglass False
Exit Sub

cmdCreateGraph_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Resume cmdCreateGraph_Exit



End Sub