
Selecting the last file in a folder.
I agree with Dev (I send my regards to master) I send an example :
'************************** code start ****************************
Sub Numarator()
Dim YdkDosya(1 To 10) As Variant
Dim MyStamp(1 To 10) As Variant
Dim frmMess As New frmMessager
On Error GoTo Hata
'TargetFolder is a global varilable, could be anything else
YdkDosya(1) = Dir(TargetFolder & "*.BCK") 'or whatever your file
extension is
i = 1
While YdkDosya(i) <> Empty
i = i + 1
YdkDosya(i) = Dir
Wend
bcksay = i - 1 ' number of matching files
'This is the crucial part
For i = 1 To bcksay
MyStamp(i) = FileDateTime(TargetFolder & YdkDosya(i))
Next
'select the first and compare with the others
NewestBackup = 1
For i = 2 To bcksay
If MyStamp(i) > MyStamp(NewestBackup) Then NewestBackup = i
Next
If bcksay <> 0 Then
StartNumber = (Mid(YdkDosya(NewestBackup), 7, Len(YdkDosya(NewestBackup)) -
9))
Else
StartNumber = 0
End If
Exit Sub
Hata:
Etiket = "Invalid Operation : Code - Numarator " & CStr(Err.Number) & vbCr &
_
"Description : " & Err.Description & vbCr & _
"Report Error code to author or check for updates."
MsgBox Etiket, vbCritical
End Sub
'************************** code end ****************************