Consulting

Results 1 to 4 of 4

Thread: Solved: D*MN Column Headers!!!!

  1. #1

    Solved: D*MN Column Headers!!!!

    When importing data into Excel via SQL query integrated into VBA code - how do I just import the data - without the header columns?

    When I run the query to pull 1 row off an access database it is returning the coumn headers for each row - which is pretty annoying.

    There doesn't seem to be any help on the almight google!

    Your collective genius will be most greatly appreciated.

    Thanks in advance!

    Max

    p.s. this post is also up in the Excell Help forum. Wasn't too sure where to post this!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Max, just use ADO with your SQL query string. The returned recordset has items and headers separate, so you can ignore headers.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    I'm fairly new to this. How do I do that?

    This is my query string....

    [vba] varConnection = "ODBC; DSN=MS Access Database;DBQ=C:\Users\*****\Documents\IDSDB.mdb; Driver={Driver do Microsoft Access (*.mdb)}"
    varSQL = "SELECT [instructionsreceivedDS-090816].[Instruction Reference],
    [instructionsreceivedDS-090816].[Instruction Type],
    [instructionsreceivedDS-090816].[Instruction Received],
    [instructionsreceivedDS-090816].[Given Name],
    [instructionsreceivedDS-090816].[Surname],
    [instructionsreceivedDS-090816].[Records],
    [instructionsreceivedDS-090816].[Instructor Name]
    FROM [instructionsreceivedDS-090816]
    WHERE Left( [instructionsreceivedDS-090816].[Instruction Reference], 6) = '" + y + "'"

    With ActiveSheet.QueryTables.Add(Connection:=varConnection, Destination:=Cells(i, 1))

    .CommandText = varSQL

    .Name = "Query-39008"

    .Refresh BackgroundQuery:=False

    End With[/vba]

  4. #4
    I've done it with the help of Brad the legend:

    Dim varConnection
    Dim varSQL
    Dim SQL As String
    Dim SQLrs As New ADODB.Recordset
    Dim SQLcon As New ADODB.Connection

    - code -

    SQLcon.ConnectionString = varConnection
    SQLcon.Open
    SQLrs.Open varSQL, SQLcon, adOpenStatic


    Thanks for the ADO hint XLD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •