Results 1 to 4 of 4
  1. #1
    wao5012 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2024
    Posts
    1

    Updating Column Data types within an existing vba code

    Public Function import_data_files()


    Dim report_path As String, file_name As String

    report_path = "C:\Raw Data"
    file_name = Dir(report_path & "*.csv", vbDirectory)

    Do While file_name <> vbNullString


    DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & file_name, True
    file_name = Dir
    Loop
    MsgBox "Data files imported.", vbInformation


    End Function

    I have the above vba code to pull .csv files from a specific folder. I would now like to update the column data types so that all the information flows into the access table. I have a column called Project number and the data contained in the columns are numbers and text. when I pull them into access it only gives me the cells with numbers and not text. I need to convert the entire column to a text as it is being brought into access. Is this possible if so, how would i do this.

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    One approach is to link to the csv file as a table (or tables) then query what you need into a table(s) that has the proper field data types. So if the csv field is text (e.g. $1.00 as text) when you query that into the db table in the Currency field (because that would be the field data type you would have used) it should work. As long as the text conforms to the table field data type you should be ok. If a csv field is 1.25 (again, it is text) and you try to put in in an integer field it will fail because integers cannot contain decimal portions.
    Last edited by Micron; 07-15-2024 at 02:14 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    I wonder if you can bring the data into Excel using PowerQuery, change the data types there, and then import into Access.

    The more I use Excel, the more I think Access is stuck in the 1990s.

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    following method worked best for me: import all columns in an import table where all fields are text(max) columns and from there pump the data in the correct tables, where necessary using convert functions to get them in the correct data type.

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

Similar Threads

  1. Importing Data from XML and then Updating Existing Table
    By venom in forum Import/Export Data
    Replies: 23
    Last Post: 05-10-2021, 08:01 AM
  2. Replies: 3
    Last Post: 08-05-2019, 02:41 PM
  3. Replies: 17
    Last Post: 11-05-2017, 01:09 PM
  4. Updating the Existing record with new data
    By rd.prasanna in forum Import/Export Data
    Replies: 4
    Last Post: 10-02-2013, 07:04 AM
  5. updating existing report with new data in table
    By newtoaccess123 in forum Reports
    Replies: 2
    Last Post: 10-18-2011, 09:50 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