Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44

    Import of long text is truncated at 255 chars

    Hi,



    You helped me a lot setting up the following code:
    Code:
    Private Sub btnImport_Click()
    Dim fDialog As FileDialog
    Dim strFileName As String
    Dim db As DAO.Database
    Dim sqlStr As String
    Dim varFile As Variant
    
    Me.FileList.RowSource = ""
    
    On Error GoTo errHandler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    Set db = CurrentDb
    
    With fDialog
        .AllowMultiSelect = True
        .Title = "Please select one or more files"
        .Filters.Clear
        .Filters.Add "Excel Spreadsheets", "*.xls, *.xlsx, *.xlsm, *.xlsb"
        If .Show = True Then
            For Each varFile In .SelectedItems
                Me.FileList.AddItem varFile
                strFileName = varFile
                sqlStr = "INSERT INTO tblTransaction (YearMo, Entity, Acct, ActDKK, FcDKK, ActLocCur, FcLocCur, Comment) " & _
                "SELECT * FROM (SELECT YearMo, Entity, Acct, ActDKK, FcDKK, ActLocCur, FcLocCur, Replace([Comment1],Chr(10),Chr(13) & Chr(10)) " & _
                "As Comment FROM [DB$] AS xlData IN '" & strFileName & "'[Excel 12.0;HDR=yes;IMEX=2;ACCDB=Yes])"
                db.Execute sqlStr
                MsgBox strFileName & vbCrLf & db.RecordsAffected & " records imported"
            Next
         Else
           MsgBox "Import selection was cancelled."
           Exit Sub
        End If
    End With
    
    exitHere:
    Set fDialog = Nothing
    Set db = Nothing
    Exit Sub
    During the testing I didn't consider triggering length limits (apparently 255 characters seem to be an issue as on more than one occasion the reference is http://allenbrowne.com/ser-63.html, which I've been reading through).

    I'm still having problems understanding why the import of below Excel example...
    Click image for larger version. 

Name:	2022-09-06_11-22-30.png 
Views:	25 
Size:	20.0 KB 
ID:	48641

    ...results in being truncated as below.
    Click image for larger version. 

Name:	2022-09-06_11-22-00.png 
Views:	25 
Size:	12.4 KB 
ID:	48640

    The issues described in above link (aggregation, uniqueness, format property, union query, concatenated fields, row source) do, as far as I see it, not apply to my coding.

    I also tried a few shots in the dark based on recommendation for other users facing this issue (e.g., put the memo field in the front in the related statements), however this did not help resolving the issue.

    So obviously the question is: How can I make sure, that the whole content of the affected field can be imported into Access?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    did you also try:
    A:
    1. attached the excel sheet as external table,
    2. run append query

    B: try import command
    docmd.ImportSpreadsheet

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Try removing the replace command from the import routine, I suspect that is forcing the field to short text as far as Access is concerned.

    You can always update the crlf later.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    Thanks for the quick answers. I will look into it and will revert asap.

  5. #5
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    @Minty: This would have been the preferred approach, as you say, the replace can also be run subsequent to the import. However it still truncates after 255 chars:
    Click image for larger version. 

Name:	2022-09-06_13-00-13.png 
Views:	26 
Size:	9.7 KB 
ID:	48642

    I look now into @ranman256 solutions, however that brings me partly back where I initially started from here, where there were valid arguments to rather go with a query than a transferspreadsheet. Also your solution A will not be viable, as there will be 30 - 40 Excel files per month, which will be imported in the DB.

    I also tried the standard import function (External data / New data source / from file / Excel). This also truncates at 255.

  6. #6
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    I tried linking the table to simply see if the complete field content would be available. But same behavior here, truncation after 255:
    Click image for larger version. 

Name:	2022-09-06_13-26-04.jpg 
Views:	25 
Size:	44.6 KB 
ID:	48643

  7. #7
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    I'm getting closer to the root cause of the problem. It must have to do with the fact, that Access merely inspects the first few (likely 8) rows of data and decides what it applies no matter if it's a designated LONG field. This article, although not directly related, helped me isolating the issue.

    When I put a long (> 255 character) comment in the first to import row, then Access reliably imports this and all subsequent short/long comments correctly.
    Click image for larger version. 

Name:	2022-09-06_13-54-33.png 
Views:	25 
Size:	15.8 KB 
ID:	48646

    So a solution could be to put a dummy record with a 'real' long text to start the import, however this is of course not ideal. But can I 'force' Access somehow else to respect the LONG field setting?

  8. #8
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    Think this might work: As soon as our IT will help me adjusting the 8 records to 1000. I will test again and revert with results.
    Click image for larger version. 

Name:	2022-09-06_14-19-41.png 
Views:	24 
Size:	66.7 KB 
ID:	48647

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,551
    Can't you just use a specification?
    https://www.google.com/search?q=acce...%20for%20excel
    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

  10. #10
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    Tried that, post #5
    I also tried the standard import function (External data / New data source / from file / Excel). This also truncates at 255.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Import/Export Saved Specification Name argument is not available with TransferSpreadsheet, it is with TransferText.
    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.

  12. #12
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    Still waiting for our IT to bypass the registry limitation. I'd really like to test this.
    The bypass solution with the dummy record works fine and I applied this short term to fix the issue.

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    I also tried the standard import function (External data / New data source / from file / Excel). This also truncates at 255.
    it doesn't if you specify memo/longtext.
    Click image for larger version. 

Name:	image_2022-09-07_100702134.png 
Views:	13 
Size:	10.8 KB 
ID:	48652

    Pretty sure changing typeguessrows to 0 will cause all rows to be evaluated.

    Another method is to save the xl file as a .csv, then instead of

    "FROM [DB$] AS xlData IN '" & strFileName & "'[Excel 12.0;HDR=yes;IMEX=2;ACCDB=Yes]"

    use

    "FROM [TEXT;DATABASE=" & strPath & " ;HDR=Yes]." & strcsvFileName & ".csv"

  14. #14
    daredan is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    44
    The registry fix works!
    Click image for larger version. 

Name:	2022-09-07_12-55-52.png 
Views:	13 
Size:	31.2 KB 
ID:	48653


    However I'll go with the long text dummy record, because this will be easier instead of asking any database user doing import tasks to ask IT to increase the limit.

    @CJLondon: Only saw your input now.

    The standard import function didn't give me the option specifying data types per field (probably changed from Access2010 to Access365?). I could only select worksheets/named ranges and if the first row contains headings or not. Then it went straight to the import.

    Yes 0 in this registry value will go through all records. However in my case 1000 is sufficient as currently there are approx. 830 records per import. That also will not fluctuate much in the future.

    The .csv approach is interesting, however in my case too cumbersome to consider. Our process is to distribute an Excel template, entities/clusters will update some financial information and fill in explanations and send the file back. Then I 'bulk' import around 30 files in one go, so that people looking at numbers/explanations don't have to go through lots of Excel files, but simply open reports in the database.
    Last edited by daredan; 09-07-2022 at 05:13 AM. Reason: @CJLondon

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    not that cumbersome, don't have the time to provide the proper code, but would be along the lines of

    Code:
    open an excel application object
    for each workbook
        open workbook
        select appropriate worksheet if necessary
        save as .csv (could be a generic import name)
        close workbook
        import .csv
    next workbook
    providing your template does not include formulae (or at least not required once value is calculated), you could just send out a .csv which will automatically open with excel

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 07-25-2022, 05:36 AM
  2. How can I import long text with line breaks from .XML
    By PeterG in forum Import/Export Data
    Replies: 3
    Last Post: 07-11-2020, 03:54 PM
  3. Replies: 1
    Last Post: 08-29-2016, 07:50 PM
  4. Replies: 14
    Last Post: 12-28-2015, 07:51 AM
  5. Replies: 1
    Last Post: 02-25-2015, 04:40 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