我正在尝试导入一个CSV文件,该文件是从我开发的web表单中创建的。当表单提交时,它会在我的CSV中创建一个包含大量客户信息的记录。
根据需求,我需要将其放入CSV中,然后将其分别导入Access数据库供其他人使用(服务器安全性需要两个步骤)。
我尝试这样做的方式是使用一个简单的表单,其中有一个按钮在Access中,简单地说是Import,只要用户需要它,它就会拉动CSV的更新。
我的错误让我困惑,因为它表明
“字段'F1‘在目标表”应用程序"中不存在
我的CSV中没有标记为F1的字段,甚至没有任何包含' F1‘的记录,而且我的访问表应用程序中也没有名为F1的字段(很明显)。
这里是我的VB模块代码,来自Access
Option Compare Database
Sub ImportingCSV()
Function Import()
On Error GoTo Macro1_Err
DoCmd.TransferText acImportDelim, "", "Applications", "C:\Users\ALee\Documents\formTesting22.csv", False, ""
Import:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function这是我的CSV文件格式(为您的可读性用空格)
OPUCN#WVQNAJT4PD,
2017.05.03,
test,
v,
90545452929,
4062033985,
No,
VM@TEST.VMTEST,
10003937683827,
test,
test,
689 395 3967,
2048 2983999,
No,rle@don.ca,
111 e Streeth south,
12,
Temporary,
Commercial,
100,
200,
300,
208/120V,
Three-Phase,
Underground (UG),
Ganged Position*,
23,
"dsbsdhfbslhfbshfbsdhlfbgshdfgsfslfgljshgfljshgfljshgflsj"错误告诉我,第二个电话号码的字段(CSV中的“4062033985”)在表应用程序中没有字段,但它有!CSV中的"F1“是Customer Mobile。当我通过Access的导入向导手动导入时,这很好。

希望有人能指出正确的方向,不熟悉VB脚本或宏的访问。
发布于 2017-05-09 14:45:05
不要导入文件。
将csv文件链接为一个表。然后创建一个查询来读取和转换(purify)数据。
使用此查询作为进一步处理日期的源,例如将数据附加到其他表中。
发布于 2017-05-09 20:05:30
CSV文件是电子表格..。试着..。
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml,[YourDestinationTable],"C:\YourFileDirectoryPath, filename, and extension",true,[Spreadsheet name if multiple sheet names]发布于 2017-05-26 21:00:37
做这种事有各种各样的方法。这当然是最简单的方法。
Private Sub Command0_Click()
DoCmd.TransferText acImportDelim, "", "Book1", "C:\your_path_here\Book1.csv", True, ""
End Sub假设您想要将几个CSV文件,都是相同的类型,导入到同一个表中。只需运行下面的脚本。
Option Compare Database
Option Explicit
Private Sub Command0_Click()
DoImport
End Sub
Function DoImport()
Dim strPathFile As String
Dim strFile As String
Dim strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
' Change this next line to True if the first row in CSV worksheet
' has field names
blnHasFieldNames = True
' Replace C:\Documents\ with the real path to the folder that
' contains the CSV files
strPath = "C:\your_path_here\"
' Replace tablename with the real name of the table into which
' the data are to be imported
strFile = Dir(strPath & "*.csv")
Do While Len(strFile) > 0
strTable = Left(strFile, Len(strFile) - 4)
strPathFile = strPath & strFile
DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
' Kill strPathFile
strFile = Dir()
Loop
End Function您也可以执行各种其他细化;使用msoFileDialogFilePicker导航到文件;您可以遍历记录集并将它们逐一加载到您的表中。正如Gustav所建议的,您可以链接到您的文件(暂存)并将记录写入表(生产)。您可能应该尝试所有这些方法,并使用
https://stackoverflow.com/questions/43872255
复制相似问题