Hello, (this should/had to be an easy one…)
I want to process a number of files in a directory, using a loop with the old Dir function. BUT…
1. It renders all files while testing with an ’empty’ loop, like:
Dim strDir as String
Dim strFile as String
strDir = CurrentDBDir ‘(1)
strFile = Dir(strDir)
Do Until strFile = “”
MsgBox strFile
strFile = Dir
Loop
‘ (1) MVPS custom function returning database folder path
2. It renders only *one* result (i.e. the first file found?) after having added some extra code:
…
Do Until strFile = “”
MsgBox strFile
‘Only handle the suitable files
If Right(strFile, 6) = “E1.doc” Then
‘… ‘copy & rename file
‘… ‘use Word automation to open renamed file & perform actions
ElseIf Left(Dir$(CurrentDb.Name), Len(Dir$(CurrentDb.Name)) – 4) = Left(strFile, Len(strFile) – 4) Then
‘do nothing
Else
‘… ‘register
End If
strFile = Dir
Loop
Does anyone have any idea what’s happening here? The only workaround I can imagine is using the ’empty’ Dir loop first to fill a recordset/array filled with all ‘suitable’ files info and process the files in this list lateron, but it’s hard to accept this would be the best practice…
Hasse
p.s. Even with only the If… then… else… lines activated & all other lines deactivated (as comment lines), the loop fails.