Results 1 to 2 of 2
  1. #1
    Steven Seagal is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    20

    How can I KEEP blank characters when exporting from Access to Excel?

    I made a query in Access where each record has to have exactly 150 characters. I configured it so that I have a ton of spaces at the end and just do something like left([fieldname] & " ", 150)



    Now this works in the query - each record does indeed have 150 characters, but when I export this query to excel either manually or vba, each record stops where the last non-blank character was, so everything is like 70 characters long or something.

    I don't think it's an issue with my code, but surely there's a way to keep those blank characters in a specific cell ,correct?

    If so, how?

    Code: So the query QPCFALL contains the right number of characters, 150, when I view in Access, but when exporting to Excel, it stops at the last non-blank.
    Code:
    Private Sub Command2_Click()
    On Error Resume Next
    Dim exlApp As Object 'Excel.Application
    Dim exlBook As Object 'Excel.Workbook
    Dim exlSheet As Object 'Excel.Worksheet
    Dim strProjPath As String
    Dim stDocName As String
    DoCmd.SetWarnings False
    Kill "U:\path.xls"
    strProjPath = "U:\path"
     
    DoCmd.TransferSpreadsheet acExport, , "QPCFALL", "U:path", False, "PCF"
    Set exlApp = CreateObject("Excel.Application")
    Set exlBook = exlApp.Workbooks.Open("U:\path.xls")
    
    Set exlSheet = exlBook.Worksheets("PCF")
    exlSheet.Activate
    Call exlSheet.Range("A1:a1").EntireRow.Delete
     
    exlApp.Visible = True
    DoCmd.SetWarnings True
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Need custom function to create a string value padded with spaces
    Review http://www.developerbarn.com/communi...oft-access.24/
    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.

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

Similar Threads

  1. exporting data from access to excel
    By tariq nawaz in forum Access
    Replies: 3
    Last Post: 09-06-2012, 09:29 AM
  2. Lost characters when exporting reports to pdf
    By QTT in forum Import/Export Data
    Replies: 3
    Last Post: 08-29-2012, 05:05 PM
  3. Replies: 1
    Last Post: 08-22-2011, 02:09 PM
  4. Exporting Access queries to Excel
    By dbDamo in forum Import/Export Data
    Replies: 2
    Last Post: 09-22-2009, 01:42 AM
  5. Replies: 0
    Last Post: 06-05-2009, 10:47 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