Results 1 to 5 of 5
  1. #1
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136

    Export Query to .ODS file starting at a specific cell


    HMRC (the UK Revenue Commissioners) are introducing online claiming of tax refunds for Charitable Donations. Their spreadsheet is in .ODS format and the data must be entered as shown in the attached sample (which is a zipped Excel version of their spreadsheet). While I am proficient at developing Access, I am a rookie when it comes to VB. I have a query (let's call it 'Claim') that will produce the data in the correct format. How can I get this data automatically transferred to the spreadsheet (call it 'Claim1' for convenience) starting at cell C25?

    I have seen some examples of something similar but am at a loss to translate it into a format that I need. Can someone help me please? I'm pretty good at cutting & pasting!
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    First, can Access even connect to ODS file? (I doubt it.) If not, must convert to a format Access can work with. You apparently have Excel available.
    Here are threads that demonstrate writing data to/from Excel.
    http://forums.aspfree.com/microsoft-...el-413629.html
    http://forums.aspfree.com/microsoft-...le-413493.html

    Need to set VBA Reference to Microsoft Excel x.0 Object Library

    In your case you want to open an existing workbook, not create a new one. Another example:
    Code:
    Private Sub ExportExcel()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim oExcel As Excel.Application
    Dim oBook As Excel.Workbook
    Dim intRow As Integer
    Set cn = CurrentProject.Connection
    Set rs = New ADODB.Recordset
    Set oExcel = CreateObject("Excel.Application")
    Set oBook = oExcel.Workbooks.Open("path\filename.xlsx")
    intRow = 25
    rs.Open "SELECT * FROM tablename;"
    While Not rs.EOF
    'code to write data to cells of worksheet, see other examples
    Wend
    oExcel.Visible = True
    Set oBook = Nothing
    Set oExcel = Nothing
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Thanks June7 for the guidance. You seem to be correct that I can't copy data direct from Access to a .ods file. However I have used a combination of bits and pieces from where you directed me to and have got a working button! I'm not sure whether I have some unnecessary elements in my coding but it produces the end result that I need! I end up with the HMRC .ods spreadsheet open, covered by a new .xls spreadsheet into which the output of my Access query has been pasted. Because it doesn't hold the date formatting from the query - dd/mm/yy - I have to correct this in the Excel file - (hence the message box which I have shortened below). I then copy and paste this data into the .ods spreadsheet. The following is my code. If you think I can delete any of the elements I would be happy to take your further advice. But don't waste much time on this as I can leave it the way it is. Do you have any idea why the date formatting is not held? It appears as d-mm-yy.

    Thanks again for your help.

    Dim app As Excel.Application
    Dim xl As Excel.Workbook
    MsgBox ("If the Donation Date ........")
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Gift Aid Claim (Spring) (New)", "C:\Our Folders\BWMC\Blank.xls", True
    Set app = CreateObject("Excel.Application")
    Set xl = app.Workbooks.Open("C:\Our Folders\BWMC\Blank.xls")
    app.Visible = True
    Set ws = xl.Worksheets(1)
    Set ws = Nothing
    Set xl = Nothing
    FollowHyperlink "C:\Our Folders\BWMC\gift_aid_schedule.ods", , True, True
    FollowHyperlink "C:\Our Folders\BWMC\Blank.xls", , True, True

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Does this help explain date issue http://allenbrowne.com/ser-36.html

    TransferSpreadsheet method does not require Excel objects. Try just:

    MsgBox ("If the Donation Date ........")
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Gift Aid Claim (Spring) (New)", "C:\Our Folders\BWMC\Blank.xls", True
    FollowHyperlink "C:\Our Folders\BWMC\gift_aid_schedule.ods", , True, True
    FollowHyperlink "C:\Our Folders\BWMC\Blank.xls", , True, True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Thanks for everything.

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

Similar Threads

  1. Export Query to specific excel sheet
    By Perceptus in forum Queries
    Replies: 2
    Last Post: 12-20-2012, 11:50 AM
  2. Export Query to Specific Sheet and Rows/Columns
    By chewbears in forum Queries
    Replies: 7
    Last Post: 11-30-2011, 09:44 AM
  3. import specific cell from excel to access
    By maneuk in forum Import/Export Data
    Replies: 10
    Last Post: 07-01-2011, 06:24 AM
  4. Export a value to specific Excel cell
    By gg80 in forum Import/Export Data
    Replies: 5
    Last Post: 07-23-2010, 01:58 PM
  5. Hyperlink to a specific Field/Cell?
    By tbutters in forum Database Design
    Replies: 8
    Last Post: 06-04-2010, 12:27 PM

Tags for this Thread

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