Adding Unnecessary Blank row on import from Access 2010 (Windows 7)

nstratton

New Member
Joined
Sep 17, 2015
Messages
3
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?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
CStr(lngLastDataRow + 1

You're telling it to paste it below your last row PLUS 1. :)

This probably means the "last row" is selecting the row below your actual last row of data.
 
Last edited:
Upvote 0
I noticed it as soon as I posted the question. I feel like a moron. Took out the +1 and of course it works like expected.
I appreciate the quick response
 
Upvote 0

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top