Results 1 to 10 of 10
  1. #1
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29

    Trying to create an Excel spreadsheet

    I am trying to get the table field names as the cell names, I thought this was possible, but all I get is the file names as the first row of data.

    Dim FolderPath As String
    FolderPath = "C:\Access\Meter Readings for " & CurrentMonth (Doesn't need to be there, if it is, will overwrite it.)



    DoCmd.OutputTo ObjectType:=acOutputTable, ObjectName:="PropertyTB", OutputFormat:=acFormatXLS, OutputFile:=FolderPath (Tried this, doesn't seem to work very well.)

    DoCmd.TransferSpreadsheet acExport, , "PropertyTB", FolderPath (This works but doesn't alter the cell titles (still A B C etc), puts table field names as first line.)

    DoCmd.TransferSpreadsheet acExport, , "PropertyTB", FolderPath, True (Same as above)

    MsgBox "Done, transfered PropertyTB to Meter Readings for " & CurrentMonth

    Any help would be appreciated, thanks Roy

  2. #2
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    154
    This worked for me.
    Private Sub Command0_Click()
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Flour Percentage", "C:\Users\User\Desktop\ExportedXLS", True
    End Sub

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    AFAIK, Excel column letters cannot be replaced. Column letters and row numbers must be present in the Excel grid frame. First row of sheet is supposed to be custom column headers if you want any.

    madpiet, is your example missing a dot for the file extension? What do you mean by "worked" - are the column letters in frame actually replaced with table fieldnames?

    Rico, why not use acSpreadsheetTypeExcel12XML and .xlsx extension?
    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.

  4. #4
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29
    This site seems to have been down for a couple days, (in Australia).
    Give me time to check out the 2 replies and I will get back to you.
    Thanks, Roco

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I don't think cells have names - they have addresses. Columns have letters to id them, but those aren't names either AFAIK. So maybe you want your Access table field names as Excel column headers?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Excel column letters cannot be replaced. Column letters and row numbers must be present in the Excel grid frame.
    but you can hide them - on the ribbon - Page Layout>untick Headings>View
    Click image for larger version. 

Name:	image_2023-09-15_001717832.png 
Views:	24 
Size:	20.2 KB 
ID:	50761

    to do this automatically, you would need vba code to untick the box. To determine the code, record a macro in excel doing the actions required and then after you have created your file, using vba open it and apply the recorded code - which as I recorded it would be

    Code:
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    
        ActiveWindow.DisplayHeadings = False
    End Sub
    You may have other requirements such as naming sheets, hiding gridlines, apply formatting, freeze top row, autosize columns as well, so record these actions at the same time

  7. #7
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29
    Ok, thanks to everyone, I think I have enough info to fix my problem now.
    Rico

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Well, please post your solution when you have it.
    These forums are here to help others as well?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29
    I wrote a small ms access program to record the electrical meter readings, once a month, for our village of 282 properties.
    Once recorded, my access program produced an Excel Spreadsheet to be passed on to our accounts dept.
    I was hoping that the table field names could replace the spreadsheet Columns names. (1 2 3 etc). you now tell me that this can't be done and the field names end up as the first row of the spreadsheet.
    So, I will delete the first row after I produce the spreadsheet, because the accounts dept say they don't want it there.
    I'm happy, Rico

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Well if you're happy with what you've got then carry on. Otherwise I wonder if Automation is what you can make use of. From Access, you could do practically anything with Excel. That includes creating a sheet or even a workbook and sheet, or populating a sheet with data below the sheet column headers, or within a named range, or creating the headers and populating the sheet...

    and somewhere within all of that you'd be able to get table names and/or field names for your Excel headers - if that's what you want, but not clear to me what you want from Access on the Excel side.

    This is where I'd direct anyone for Automation code
    http://www.accessmvp.com/KDSnell/EXCEL_MainPage.htm
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 6
    Last Post: 07-10-2019, 07:34 PM
  2. Replies: 4
    Last Post: 03-19-2019, 08:35 AM
  3. Replies: 2
    Last Post: 02-13-2015, 12:34 AM
  4. Replies: 1
    Last Post: 08-05-2013, 03:47 PM
  5. Create Report that looks like a spreadsheet
    By Hank153 in forum Reports
    Replies: 10
    Last Post: 12-10-2012, 10:08 PM

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