Results 1 to 11 of 11
  1. #1
    RodG is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    2

    Question Access overriding my choice of field type when importing CSV.


    I'm trying to import a large CSV file (700,000+ rows) directly into a table. Some columns in the CSV file are nearly all numeric except for an occasional character. Knowing this I set the field in the table I am importing into as Short Text. Access seems to ignore this and treats the field as if it is Long, consequently the character strings which will easily fit into the field are ignored.
    I have a similar problem with another field, this is all numeric, however the number is too long to fit into Long, so I set the field to Short Text again. Again Access thinks it knows better and imports as Long, then doesn't save it as the number won't fit into Long.
    I also have similar problems with dates, The CSV file occasional has something like -/-/1986. I ask for it to go into a text field, but again it ignores the field type.

    Altering the CSV file is not really an option. Any suggestions much appreciated.

    R

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    How are you importing your CSV? A CSV file is text. Just import it as a text file.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,969
    ItsMe, isn't that what poster is attempting?
    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
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    ItsMe, isn't that what poster is attempting?
    It does not seem so. Perhaps they are using Excel. Maybe linking to it.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,969
    The poster says 'import a large CSV' but you think maybe they are not actually directly importing the CSV? That does make sense with the described issue.
    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.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Yeah, there seems to be a contradiction and it would help if some things were clarified.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is the CSV file being imported using an import specification? That should force the data type.

  8. #8
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,451
    Knowing this I set the field in the table I am importing into as Short Text. Access seems to ignore this and treats the field as if it is Long, consequently the character strings which will easily fit into the field are ignored.
    A text field will accept any data up to it's defined size, so what you are suggesting does not make sense. The problem you describe relates to importing to a new table or an incorrectly defined specification. I would check that it is set up correctly and not treating a text field as long.

    If left undefined Access (and excel and many other systems for that matter) will inspect up to the first 16 rows or so to determine field type - so if those rows only contain numeric data it will treat the field as numeric - possibly solvable by sorting the file to ensure the 'correct' field types are in the first 16 rows, but with 700k records....

    It may be your initial 'test' import has set an incorrect specification and your subsequent attempts are using this wrong specification

  9. #9
    RodG is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    2
    Quote Originally Posted by Ajax View Post
    It may be your initial 'test' import has set an incorrect specification and your subsequent attempts are using this wrong specification

    Just to clarify, I am importing using {External Data}{Text File}.
    As I have several difficult fields sorting is not an option, and anyhow, I think some of the files exceed Excel's row limit.
    I was aware that if I let Access decide its own field types for the table it would get it wrong so the destination fields are set to Text without doubt.
    Will Access retain some memory behind the scenes of what it did before and reuse this?

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    What I do is use the Wizard and let the wizard create a table for me. Then, I use the wizard again and select the table previously created as the destination. On the second Wizard, I save the procedure and give it a name. When I look at the table, all of the fields will be of data type Text. I then use the name I gave the saved procedure when I call the saved procedure via VBA code.

    I treat the table created by the first Wizard as a temp table. I do not ever delete the table. However, I delete the data. Before and or after I run an import process, I delete all of the data in my temp table.

    After I run the stored import procedure, I need to validate and append the imported data to a production table. I use VBA and specific data types for my variables as I run Gated Checks. One way is to nest DAO Recordsets and loop.

  11. #11
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,451
    I was aware that if I let Access decide its own field types for the table it would get it wrong so the destination fields are set to Text without doubt.
    By destination tables, I presume you mean the table. What I am referring to is the specification you can complete when using {External Data}{Text File}. When in this process, click on the advanced tab

    Will Access retain some memory behind the scenes of what it did before and reuse this?
    sort of - it creates a specification automatically. It cannot import without one

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

Similar Threads

  1. Replies: 2
    Last Post: 06-04-2014, 11:12 AM
  2. Replies: 9
    Last Post: 11-20-2013, 03:16 PM
  3. Choice of Male or Female. What data type to use?
    By Access_Novice in forum Access
    Replies: 5
    Last Post: 09-19-2013, 09:06 PM
  4. Multiple choice in a single field
    By fabads in forum Access
    Replies: 6
    Last Post: 05-21-2013, 11:45 AM
  5. Replies: 5
    Last Post: 01-09-2012, 05:55 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