I have an issue with the Dir
function.
Private Sub InitFileElvt()
Dim fileName As String
Dim find As Boolean
Dim trouve As Boolean
trouve = False
fileName = Dir(THEORIQUE & "\" & LibPie & CftMot & _
Mid(NoPlan, 13, 1) & Mid(VERPIE, 1, 1) & "\") 'It works here
Do While fileName > "" And Not trouve
If IsElvtFile(fileName) Then
trouve = True
pathFileElvt = THEORIQUE & "\" & fileName
End If
fileName = Dir() 'An error here
Loop
If Not trouve Then
pathFileElvt = "empty"
End If
End Sub
Private Function IsElvtFile(ByVal fileName As String) As Boolean
Dim lengthDeb As Integer
lengthDeb = Len(LibPie) + Len(CftMot) + 1
IsElvtFile = Left(fileName, lengthDeb) = LibPie + CftMot + Mid(NoPlan, 13, 1) And _
Right(fileName, 4) = ".ELV"
End Function
The first call to Dir
give me a file from the folder. Good. But the second call give me Run-Time Error '5': Invalid Procedure Call or Argument
What i'm missing about the Dir
Function? Apparently, that's how it have to be used.
When i'm in debug mode, in the line Do While fileName > "" And Not trouve
, my watch on dir returns the next file. After this line is executed, my watch shows the error.
There was other watch in Dir(otherPath)
...
I've removed them and now it works