Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Excel file does not load in MS access

It runs without any Error message but the files are not loaded in MS access. what could be the reason? I do have a csv file in the directory

After edit

Option Compare Database
Option Explicit

Public Function import_date_files()

    Dim report_path As String, file_name As String
    
    
    
    
    report_path = "C:\Users\gobro7\OneDrive - Levi Strauss & Co\MS access test\weekly_load"
    
    file_name = Dir(report_path & "\*.csv")
    
    
    Do While file_name <> vbNullString
        DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, "\.csv", "")), report_path & file_name, True
        file_name = Dir
    Loop
    
    MsgBox "Data loaded", vbInformation
    
         

End Function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to add a backslash between the path and the file name. You can either write

file_name = Dir(report_path & "\*.csv")
Do While file_name <> vbNullString
    DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & "\" & file_name, True
    file_name = Dir
Loop

Or you add the backslash at the end of your path definition:

' Note the trailing backslash!
report_path = "C:\Users\gobro7\OneDrive - Levi Strauss & Co\MS access test\weekly_load\"

file_name = Dir(report_path & "*.csv")
Do While file_name <> vbNullString
    DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & file_name, True
    file_name = Dir
Loop
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading