Private Sub Command38_Click()
Dim f As Object
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strUpdate As String
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Dim P As String
Dim DeleteEverything As String
DoCmd.SetWarnings False
DeleteEverything = "DELETE * FROM [ucppltr]"
DoCmd.RunSQL DeleteEverything
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.InitialFileName = "S:\Formware\outfile\ucppt12\Storage"
f.Filters.Clear
f.Filters.Add " Armored TXT Files", "*.asc"
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
P = strFolder & strFile
DoCmd.TransferText acImportDelim, "UCPP Import Specification", "ucppltr", P, False
Next
End If
strUpdate = "PARAMETERS fileName Text;" & vbCrLf & _
"UPDATE ucppltr" & vbCrLf & _
"Set [File Name] = fileName"
Debug.Print strUpdate
Set db = CurrentDb
Set qdf = db.CreateQueryDef("", strUpdate)
qdf.Parameters("fileName") = strFile
qdf.Execute dbFailOnError
Set qdf = Nothing
Set db = Nothing
Set f = Nothing
MsgBox DCount("*", "ucppltr") & " Records were imported"
End Sub
正如您从导入代码中看到的那样,我想存储文件名,虽然它确实有效,但它并不能完全按照我的需要工作。当我们为这个客户工作时,它每周吃一次 5 个文件,所以我希望它保存所有 5 个文件名,但它只保存它导入的最后一个文件名。我的问题,有没有办法将每个文件名保存到每个文件名(我对此表示怀疑)或者我可以将所有 5 个文件名保存到我导入的所有记录中,而不仅仅是最后一个文件名?
我总是可以选择只允许一次导入并使它们导入并附加表 5 次,我只是想在这样做之前检查是否有更有效的方法。
在此先感谢您在此问题上的任何帮助!