テキスト ファイルへのパスを含むテーブルを循環し、それらをデータベースにインポートする手順をまとめました。
手順 の理由: これは、毎晩更新されるテキスト ファイルに依存する多くのレポート データベースのバックエンドを構築しているためです。最近、これらのファイルのサーバー名とファイル名が変更されたので、リンク テーブル ウィザードを実行してすべてのデータ型が以前とまったく同じであることを確認する必要がないように、より信頼性の高いものを構築しようとしています。
問題: 私が抱えている問題は、With .edit .update が思ったように動作せず、テーブルの「更新済み」フィールドを今日の日付に更新することです。
これがコードです。私はまだプログラミングに慣れていないので、申し訳ありません。
Private Sub ImportAll()
' Loops through table containing paths to text files on network and imports
Dim ID As Integer
Dim netPath As String
Dim netDir As String
Dim netFile As String
Dim localTable As String
Dim activeTable As Boolean
Dim updatedTable As Date
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Tables")
Do Until rst.EOF
ID = rst.Fields("Table ID").Value
netDir = rst.Fields("Network Location").Value
netFile = rst.Fields("File Name").Value
localTable = rst.Fields("Local Table Name").Value
activeTable = rst.Fields("Active").Value
updatedTable = rst.Fields("Updated").Value
If activeTable = True And updatedTable <> Date Then
If ifTableExists(localTable) Then
On Error GoTo ImportData_Err
CurrentDb.Execute "DELETE * FROM " & localTable, dbFailOnError
netPath = netDir & netFile
DoCmd.TransferText acImportDelim, , localTable, netPath, True, ""
rst.Edit
updatedTable = Date
rst.Update
Else
netPath = netDir & netFile
DoCmd.TransferText acImportDelim, , localTable, netPath, True, ""
With rs
.Edit
.Fields("Updated") = Date
.Update
End With
End If
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ImportData_Exit:
Exit Sub
ImportData_Err:
MsgBox Error$
Resume ImportData_Exit
End Sub
ありがとうございました。