Code:
Private Sub cmdCreateChart_Click()Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim objXL As Object
Dim lngLastDataRow As Long
Set objXL = CreateObject("Excel.Application")
Set dbs = CurrentDb
'Get the parameter query
Set qdf = dbs.QueryDefs("qryCharts")
'Open a Recordset based on the query
Set rst = qdf.OpenRecordset()
With objXL
.Visible = True
.UserControl = True
With .Workbooks.Open("C:\Users\cole.stratton\Documents\Form1")
lngLastDataRow = .Worksheets("ChartData").Cells.SpecialCells(11).Row
.Worksheets("ChartData").Range("A" & CStr(lngLastDataRow + 1)).CopyFromRecordset rst
.Worksheets("ChartData").Range("A:D").RemoveDuplicates Columns:=4
End With
End With
rst.Close
objXL.WindowState = xlMaximized
End If
Set rst = Nothing
Set objXL = Nothing
End Sub
I am using the code above to bring data into an excel workbook from an access database to create charts (since Access charting is an absolute pain). There are no errors occurring, however when the code is run a blank line is being inserted before the import data instead of the data being added directly under the existing data. Any ideas what might be making this happen?