I am using MS Access 2010. I have the following line of code within part of a larger code:
report_path = "C:\Users\HBee\Downloads\"
When I run the vba as a function via macro I get the following error:
Run-time error '3191':
Cannot define field more than once.
I know it is the way I have defined the report_path because when I use a different path (one that doesn't actually exist on the machine) it works. I'm using a work laptop so we have those virtual drives etc. This is essentially what my drives look like:
My documents are located in the following place:
"\lxxxxxx-mp-ns1\user$\HBxxxxx\
If I did want to define the directory in my documents I'm not sure how I would write that. But any ideas on what I'm doing wrong here?.
Option Compare Database
Option Explicit
Public Function import_data_files()
Dim report_path As String, file_name As String
report_path = "C:\Users\HBee\Downloads\"
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
The code above works perfectly on another PC using MS Access 2016.
Its this file I believe causing the issue:
CodePudding user response:
Get rid of the date/time columns and it will work.