Results 1 to 13 of 13
  1. #1
    Freedox is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2020
    Posts
    6

    Lightbulb Switch off auto data type identification

    Hi, apologies in advance if this quesiton was previouly raised, but I couldn't find the answer anywhere.

    Does anyone know if there is a way to turn off or idealy set auto data type identification to "Short Text"? I believe MS Access looks at the first 24 rows and applies data type for the table. In my case first 24 (in fact 1000s ) of first column data might be a Number but I need to be Short Text as some of the numbers are alphanumeric.

    So I'm importing data first to a temp table then passing data to another table via ODBC connection. So is there a way to make sure that in temp table "tblrsSLPARENTTEMP" data type will always be set as "Short Text"?

    Set db = CurrentDb
    On Error Resume Next: db.TableDefs.Delete "tblrsSLPARENTTEMP": On Error GoTo 0
    db.TableDefs.Refresh


    DoCmd.TransferText TransferType:=acLinkDelim, TableName:="tblrsSLPARENTTEMP", _
    FileName:=strPathFile, HasFieldNames:=True
    db.TableDefs.Refresh

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    A number of ways to counter this
    1. Change your temptable to only be short text fields ?

    2. Insert a dummy row of data that contains a text string ("a" would do) in to the first row of data (I'm guessing this is excel) then remove it after you have imported it.

    3. The final one would be to create an import spec and use that, but if your fields change that won't work.
    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 ↓↓

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Instead of importing try to link the Excel file then use pass your data from that.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,420
    So I'm importing data first to a temp table

    your code is not importing, it is linking

    another method is to set HasFieldNames to false which will bring through the (text) headers so all fields will be text- then just ignore that record which should be easy to do since you are linking to the data to process on via odbc

  5. #5
    Freedox is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2020
    Posts
    6
    Quote Originally Posted by Minty View Post
    A number of ways to counter this
    1. Change your temptable to only be short text fields ?

    2. Insert a dummy row of data that contains a text string ("a" would do) in to the first row of data (I'm guessing this is excel) then remove it after you have imported it.

    3. The final one would be to create an import spec and use that, but if your fields change that won't work.
    1. I have tried importing table (not linking), then deleting values, changing data type to short text and re-importing, but once re-imported it changes data type to int which throws an error
    2. This should be automated process so this means, I don't intend to open the file and edit before import, so that won't work :/
    3. Yep, spec would work, but columns might change

  6. #6
    Freedox is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2020
    Posts
    6
    Quote Originally Posted by Gicu View Post
    Instead of importing try to link the Excel file then use pass your data from that.

    Cheers,
    Unfortunately it's CSV file

  7. #7
    Freedox is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2020
    Posts
    6
    Quote Originally Posted by Ajax View Post
    your code is not importing, it is linking

    another method is to set HasFieldNames to false which will bring through the (text) headers so all fields will be text- then just ignore that record which should be easy to do since you are linking to the data to process on via odbc
    You're right it was link not import, however, changing to import didn't do any good

    the problem with has fields is that I need to know field name as columns will not necessary be in the same squence, like name and date columns might be swithced between columns A and B

  8. #8
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by Freedox View Post
    1. I have tried importing table (not linking), then deleting values, changing data type to short text and re-importing, but once re-imported it changes data type to int which throws an error
    2. This should be automated process so this means, I don't intend to open the file and edit before import, so that won't work :/
    3. Yep, spec would work, but columns might change
    2 - You CAN automate this, just takes a few steps.

    1. Create an excel file of your CSV, you can do this in VBA from Access.
    2. Now you can check how columns of data you have, and simply insert a dummy row of text "abc123" as the first line of data in all columns, again all in VBA.
    3. Now you import to a temp table, and everything is a text value.
    4. Delete the dummy data.
    5. Delete the temp Excel file.
    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 ↓↓

  9. #9
    Freedox is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2020
    Posts
    6
    Quote Originally Posted by Minty View Post
    2 - You CAN automate this, just takes a few steps.

    1. Create an excel file of your CSV, you can do this in VBA from Access.
    2. Now you can check how columns of data you have, and simply insert a dummy row of text "abc123" as the first line of data in all columns, again all in VBA.
    3. Now you import to a temp table, and everything is a text value.
    4. Delete the dummy data.
    5. Delete the temp Excel file.
    Good idea! But instead of creating I might just add a line or two to CSV file and that hopefully will do the trick

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,420
    did you try my suggestion in post#4?

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,975
    For info, Access checks the datatype of the first 8 rows (not 24..unless its changed recently)
    I would continue to link to the Excel file or better still CSV file as that is text.
    Then create a routine to import to your Access table in which you ensure the correct datatype by using CStr(FieldName) in your append or update query / SQL string / recordset procedure.
    I have done this for years and it ALWAYS works.
    Similarly you can use e.g. CCur, CDate, CLng etc for fields where appropriate
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  12. #12
    Freedox is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2020
    Posts
    6
    Thanks everyone for suggestions, finally got around it, used similar approach that Minty suggested:

    1. Created VBA in Excel to open CSV and insert 50 lines (just in case) with dummy "text123"
    2. Save new file
    3. Perform linked import

    It did created database with short text data types.

    Again, thanks all for suggestions!

  13. #13
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,420
    seems a long way round, but if it works for you

    good luck with your project

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

Similar Threads

  1. Replies: 20
    Last Post: 09-09-2020, 10:31 PM
  2. Replies: 0
    Last Post: 09-05-2017, 10:35 AM
  3. Replies: 4
    Last Post: 02-03-2017, 12:12 PM
  4. Switch from Internal to External Data
    By raweber in forum Access
    Replies: 4
    Last Post: 10-20-2014, 01:51 PM
  5. Replies: 8
    Last Post: 12-10-2011, 04:12 PM

Tags for this Thread

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