Results 1 to 9 of 9
  1. #1
    dimitrijus99 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    13

    Importing to accsess from CSV file error

    Hi,

    have macro, which doing automatic file import to acsess DB. After I run the query it's showing me error (addind print screen). When pressing debug it's showing error on code line: DoCmd.TransferSpreadsheet acImport, , "TBL_ADD_VALUE_Genesys-temp", strfolder & "" & strFileName, , sheetname1
    Other files are going well, just problem with this one. From where I should start checking? Click image for larger version. 

Name:	FILE.PNG 
Views:	20 
Size:	6.8 KB 
ID:	42448

    Below adding whole part of code which are doing this importing step.

    Case "ADD VALUE - Genesys"



    'Check if file has already been imported
    If DCount("Filename", "TBL_ADD_VALUE_Genesys_ImportedFiles", "Filename=""" & strFileName & """") = 0 Then
    Dim sheetname1 As String
    ' now have here problem with macro, need separate sheet name withouth format because now excel didnt understand which sheet need to take
    sheetname1 = Left(strFileName, 19)
    'sheetname1 = Left(strFileName, (Application.(".", strFileName, 1) - 1))
    DoCmd.TransferSpreadsheet acImport, , "TBL_ADD_VALUE_Genesys-temp", strfolder & "" & strFileName, , sheetname1

    CurrentDb.Execute "INSERT INTO TBL_ADD_VALUE_Genesys_ImportedFiles (Filename) " & vbCrLf & _
    "VALUES('" & strFileName & "')"
    CurrentDb.Execute "APPEND_TBL_ADD_VALUE_Genesys"
    CurrentDb.Execute "DELETE * FROM [TBL_ADD_VALUE_Genesys-temp]"
    icounter_new = icounter_new + 1
    strLastFileImported = strFileName
    strLastFileImportedDate = Format(Now, "dd/MM/yyyy")
    Else
    icounter_existing = icounter_existing + 1
    End If

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    is the csv in text format? can u open it in notepad?
    does the csv use the extension .CSV?
    does the SPEC match the format of the .csv? (is the csv comma delimited, as well as the spec file using comma delim?)

  3. #3
    dimitrijus99 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    13
    Example.zip

    Adding file example.
    ; delimited
    " for text
    Yes it is possible open with note pad.

    I also tried in describe separate import specification in MSysIMEXSpecs but this also doesn't helped or Im doing something wrong in it. At file type tried with both values, 850 and 1252

    DateDelim DateFourDigitYear DateLeadingZeros DateOrder DecimalPoint FieldSeparator FileType SpecID SpecName SpecType StartRow TextDelim TimeDelim
    - TRUE TRUE 0 , ; 850 44 Genesys 1 1 " :

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    in the SPEC settings,
    Are the fields using TRUE, set to TEXT? (since they are not boolean)

  5. #5
    dimitrijus99 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    13
    Sorry, just when copied to excel it was changed.

    Real view in access table instead of TRUE there are -1 value.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the thread title you wrote "Importing to accsess from CSV file error ", but then you are referencing an Excel sheetname. The file you posted has an extension of CSV, which is a text file. By default, Excel is set to open TXT/CSV files, but that does not mean they are spreadsheets.
    My thought is that some of the variables are NULL in the command "DoCmd.TransferSpreadsheet" because a text file does not have a "sheetname".
    Code:
    DoCmd.TransferSpreadsheet acImport, , "TBL_ADD_VALUE_Genesys-temp", strfolder & "" & strFileName, , sheetname1
    Also, there are several errors in the code snippet you posted.

    Maybe is/was was unavoidable, but it is not good to have spaces in field names.

    It would really help to see the dB and all of the code, but here is what I see...
    Code:
    .
    .
    .
    Case "ADD VALUE - Genesys"
    
        'Check if file has already been imported
        If DCount("Filename", "TBL_ADD_VALUE_Genesys_ImportedFiles", "Filename=""" & strFileName & """") = 0 Then
            Dim sheetname1 As String      '<<-- Declarations should be at the top of the routine, NOT within any looping structure.
            ' now have here problem with macro, need separate sheet name withouth format because now excel didnt understand which sheet need to take
            sheetname1 = Left(strFileName, 19)
            'sheetname1 = Left(strFileName, (Application.(".", strFileName, 1) - 1))
            DoCmd.TransferSpreadsheet acImport, , "TBL_ADD_VALUE_Genesys-temp", strfolder & "" & strFileName, , sheetname1   '<<-- the RED text doesn't need to be there - 
    
            CurrentDb.Execute "INSERT INTO TBL_ADD_VALUE_Genesys_ImportedFiles (Filename) " & vbCrLf & _          '<<-- the vbCrLf shouldn't be there
                              "VALUES('" & strFileName & "')"
            CurrentDb.Execute "APPEND_TBL_ADD_VALUE_Genesys"
            CurrentDb.Execute "DELETE * FROM [TBL_ADD_VALUE_Genesys-temp]"
            icounter_new = icounter_new + 1
            strLastFileImported = strFileName
            strLastFileImportedDate = Format(Now, "dd/MM/yyyy")
        Else
            icounter_existing = icounter_existing + 1
        End If
    .
    .
    .


    Did you know "Example.csv" has a header row (field names), 1 row of data and 4657 lines of ";;;;;;;;;;;;;;;"?

  7. #7
    dimitrijus99 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    13
    Hello,

    tried, to do changes as you wrote. Receiving same error. Yes, Example.csv always have the same header row and at others rows are data separated with ;
    Also tried add import spec using import wizard and then described this import specification in code, but this also doesn't helped.

  8. #8
    dimitrijus99 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    13
    Guys, find out how solve this problem, changed a little bit code and it's working. Thank you for support. Adding changed code below, maybe this will help for someone Instead of acImport, changed to acImportDelim and as you said deleted sheet name value. Used same import specification which was generated through import wizard.

    Case "ADD VALUE - Genesys"

    'Check if file has already been imported
    If DCount("Filename", "TBL_ADD_VALUE_Genesys_ImportedFiles", "Filename=""" & strFileName & """") = 0 Then



    DoCmd.TransferText acImportDelim, "Genesys Import Specification", "TBL_ADD_VALUE_Genesys-temp", strfolder & "" & strFileName
    CurrentDb.Execute "INSERT INTO TBL_ADD_VALUE_Genesys_ImportedFiles (Filename) " & vbCrLf & _
    "VALUES('" & strFileName & "')"
    CurrentDb.Execute "APPEND_TBL_ADD_VALUE_Genesys"
    CurrentDb.Execute "DELETE * FROM [TBL_ADD_VALUE_Genesys-temp]"
    icounter_new = icounter_new + 1
    strLastFileImported = strFileName
    strLastFileImportedDate = Format(Now, "dd/MM/yyyy")
    Else
    icounter_existing = icounter_existing + 1
    End If

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy you figured it out.

    Note that you don't need
    Code:
    ", strfolder & "" & strFileName
    nor
    Code:
    mportedFiles (Filename) " & vbCrLf & _

    It is best if you wrap the code in code tags. Hover the cursor over the # in the quick reply tool bar. Clicking on the # will insert the code tags - then paste the code between the tags.

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

Similar Threads

  1. Error on importing MS Excel file
    By Lou_Reed in forum Access
    Replies: 6
    Last Post: 09-19-2017, 06:39 PM
  2. Error on importing Excel file into MS Access.
    By Lou_Reed in forum Access
    Replies: 1
    Last Post: 09-01-2017, 02:15 PM
  3. Replies: 4
    Last Post: 09-09-2015, 12:10 PM
  4. Error when importing text file
    By narendrabr in forum Import/Export Data
    Replies: 1
    Last Post: 01-11-2013, 03:27 AM
  5. Error when Importing CSV file to Access 2007
    By narendrabr in forum Import/Export Data
    Replies: 5
    Last Post: 01-08-2013, 02:05 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