PC Review


Reply
Thread Tools Rate Thread

Data Connection: Access Query to Excel How to get rid of header ro

 
 
Der Musensohn
Guest
Posts: n/a
 
      22nd Feb 2010
Hello.

I have created a data connection in Excel to an Access query. It does
exactly what I need however the header rows of the query are imported as well
and all I want are the data in the simplest way possible.

Thanks in advance.
 
Reply With Quote
 
 
 
 
arjen van der wal
Guest
Posts: n/a
 
      22nd Feb 2010

It depends on how you setup the data connection. If you're doing it in
VBA using ADO and a reference to the query, the default is to not import the
field headings.
If you're doing it without VBA, using Get External Data on the Data
ribbon in Excel 2007 you'll get the headings.
Here's a short example using Microsoft's Northwinds sample database:

Public Sub AccessQuery()

Dim rsData As ADODB.Recordset
Dim sConnect As String

sConnect = "Provider=Microsoft.Ace.OLEDB.12.0;" & _
"Data Source=C:\VB 2008\Northwind 2007.accdb"

'create the recordset object and run the query
Set rsData = New ADODB.Recordset
rsData.Open "[Inventory on Hold]", sConnect, adOpenForwardOnly,
adLockReadOnly, adCmdTable

'put the contents of the recordset into the worksheet
Sheet6.Range("A1").CopyFromRecordset rsData
Sheet6.UsedRange.EntireColumn.AutoFit
'close the record set object
rsData.Close
'destroy the record set object
Set rsData = Nothing

End Sub

I should note that you will also have to add a reference to the ADO
object library when you create the project (In VBA editor > Tools >
References & look for Microsoft Active X Data Objects Library, whichever is
the latest edition).
 
Reply With Quote
 
EricG
Guest
Posts: n/a
 
      22nd Feb 2010
Right-click anywhere in the datarange of the query. Select "Data Range
Properties..." from the menu. Uncheck the "Include field names" box.
Refresh the query. That should do it.

HTH,

Eric


"Der Musensohn" wrote:

> Hello.
>
> I have created a data connection in Excel to an Access query. It does
> exactly what I need however the header rows of the query are imported as well
> and all I want are the data in the simplest way possible.
>
> Thanks in advance.

 
Reply With Quote
 
Der Musensohn
Guest
Posts: n/a
 
      26th Feb 2010
Thank you Arjen and Eric. I had time enough to go ahead and change the
properties as Eric suggested but thank you both.



"arjen van der wal" wrote:

>
> It depends on how you setup the data connection. If you're doing it in
> VBA using ADO and a reference to the query, the default is to not import the
> field headings.
> If you're doing it without VBA, using Get External Data on the Data
> ribbon in Excel 2007 you'll get the headings.
> Here's a short example using Microsoft's Northwinds sample database:
>
> Public Sub AccessQuery()
>
> Dim rsData As ADODB.Recordset
> Dim sConnect As String
>
> sConnect = "Provider=Microsoft.Ace.OLEDB.12.0;" & _
> "Data Source=C:\VB 2008\Northwind 2007.accdb"
>
> 'create the recordset object and run the query
> Set rsData = New ADODB.Recordset
> rsData.Open "[Inventory on Hold]", sConnect, adOpenForwardOnly,
> adLockReadOnly, adCmdTable
>
> 'put the contents of the recordset into the worksheet
> Sheet6.Range("A1").CopyFromRecordset rsData
> Sheet6.UsedRange.EntireColumn.AutoFit
> 'close the record set object
> rsData.Close
> 'destroy the record set object
> Set rsData = Nothing
>
> End Sub
>
> I should note that you will also have to add a reference to the ADO
> object library when you create the project (In VBA editor > Tools >
> References & look for Microsoft Active X Data Objects Library, whichever is
> the latest edition).

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel data connection to Access not retrieving data from single fi dandc0711 Microsoft Excel Programming 0 12th Jan 2010 03:52 PM
Connection of Excel 07 pivot table to Access Query makes DB read o Chuck W Microsoft Excel Misc 0 9th Oct 2009 03:45 PM
Data Connection from Excel to Access Deniz Yalman Microsoft Excel Programming 0 3rd Mar 2008 09:10 AM
Excel data connection to Access Sharon Microsoft Excel Misc 1 14th Feb 2008 08:33 PM
Split Excel Worksheet Data into Access header/footer Maureen Microsoft Access External Data 0 14th Nov 2003 03:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 AM.