Results 1 to 6 of 6
  1. #1
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60

    Exporting to excel

    I have a code that exports into an excel sheet. I have a good understanding how it is occurring. But now I want to add within the module that export of just one line.



    This code selects data

    Set rs = CurrentDb.OpenRecordset("SELECT Terms FROM Terms_Export WHERE Customer_Quote_Number='" & RFQNUM & "'") '

    Then tells it where to paste it.

    If rs.EOF = False And rs.BOF = False Then


    rs.MoveFirst


    If blnHeaderRow = True Then
    For lngColumn = 0 To rs.Fields.Count - 1
    xlc.Offset(0, lngColumn).Value = rs.Fields(lngColumn).Name
    Next lngColumn
    Set xlc = xlc.Offset(1, 0)
    End If


    ' write data to worksheet
    Do While rs.EOF = False
    For lngColumn = 0 To rs.Fields.Count - 1
    xlc.Offset(0, lngColumn).Value = rs.Fields(lngColumn).Value
    Next lngColumn
    rs.MoveNext
    Set xlc = xlc.Offset(1, 0)
    Loop

    End If


    rs.Close
    Set rs = Nothing

    This works great. The result is...it is entered across (based on the number of fields that is "selected") and down. I want to change this to just down. The result of the query is just one line, and I want the four fields (across) to be exported into excel straight down.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I haven't used Offset, but it would seem simplest to increment the row argument with your field count variable instead of the column argument.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60
    Not that experienced. I want to export to excel, and the results to go down the excel sheet. I found a different way around it. But I'm sure there is an easier way.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Perhaps I was thrown off by "I have a good understanding how it is occurring". Hard to say if there's an easier way without seeing what you found.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Join Date
    Apr 2017
    Posts
    1,681
    Easiest way to get data into excel from any database is to create an ODBC Query in Excel, which reads data from your database! And it gets always latest saved info at moment the query is run!

  6. #6
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    You might find this link helpful-->http://accessblog.net/2006/07/export...cel-range.html

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 12-28-2012, 02:06 PM
  2. Exporting to Excel
    By RAMSES955i in forum Import/Export Data
    Replies: 1
    Last Post: 07-04-2012, 02:06 PM
  3. Exporting to Excel
    By Andrias14 in forum Access
    Replies: 3
    Last Post: 03-20-2012, 06:04 AM
  4. Exporting to Excel
    By DreamOn in forum Import/Export Data
    Replies: 1
    Last Post: 05-23-2010, 10:27 PM
  5. Really Need Help With Exporting to Excel
    By graviz in forum Import/Export Data
    Replies: 0
    Last Post: 09-24-2009, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums