1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Sub ChargerFichiersTicket()
Dim FSO As Object, objFolder As Object
Dim objFile As Object, objText As Object
Dim sFileName As String, sTxt As String, sSQL As String
Dim sTxtA As String, sTxtB As String, sTxtC As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder(CurrentProject.Path)
With CurrentDb
'.Execute "DELETE * FROM tTck", dbFailOnError '--- efface tout, utilisé pour tests
For Each objFile In objFolder.Files
If objFile.Name Like "EJ*.txt" Then
Set objText = FSO.OpenTextFile(objFile.Name, 1)
If DCount("TckNom", "tTck", "TckNom='" & objFile.Name & "'") = 0 Then
sTxt = objText.readall
sTxtA = Mid(sTxt, 27, 78)
sTxtB = Mid(sTxt, 183, Len(sTxt) - 597 - 183 - 27)
sTxtC = Mid(sTxt, Len(sTxt) - 597, 520)
sSQL = "INSERT INTO tTck (TckNom, TckTxt, TckTxtA, TckTxtB, TckTxtC)" & _
" VALUES ('" & objFile.Name & "', '" & sTxt & "', '" & sTxtA & "', '" & sTxtB & "', '" & sTxtC & "');"
.Execute sSQL, dbFailOnError
Else
'--- normalement inutile vu que ces fichiers ne changent pas
'sSQL = "Update tTck SET TckTxt = '" & objText.readall & "' WHERE TckNom = '" & objFile.Name & "';"
'.Execute sSQL, dbFailOnError
End If
End If
Next objFile
End With
Set objText = Nothing
Set objFile = Nothing
Set objFolder = Nothing
Set FSO = Nothing
End Sub |
Partager