Selecting the last file in a folder. 
Author Message
 Selecting the last file in a folder.

Hi,

    I have a function that is executed when the database is opened. The
function passes along a file name from a folder to a text box on a form
that then uses that name to perform various tasks with the data in the
file. This is done every day and a new filename must be passed every
day. The files are name in the following manner, for example yesterday
the file would have been called   ltWed0526199. I am having trouble with
programming the module to either take the last file in the folder to
pass to the form. Even if i could somehow use the date inherently in the
file to call up the most recent file, that would also be good. Any
suggestions would be greatly appreciated.

Louis Girard



Mon, 12 Nov 2001 03:00:00 GMT  
 Selecting the last file in a folder.

Hi Louis,

  You will probably have to guess a filename and start comparing it to
existing filenames and incrementing some counter till there are no more
files found.

  Something along these lines.

 < http://home.att.net/~dashish/api/api0005.htm >

    HTH
    -- Dev


: Hi,
:
:     I have a function that is executed when the database is opened. The
: function passes along a file name from a folder to a text box on a form
: that then uses that name to perform various tasks with the data in the
: file. This is done every day and a new filename must be passed every
: day. The files are name in the following manner, for example yesterday
: the file would have been called   ltWed0526199. I am having trouble with
: programming the module to either take the last file in the folder to
: pass to the form. Even if i could somehow use the date inherently in the
: file to call up the most recent file, that would also be good. Any
: suggestions would be greatly appreciated.
:
: Louis Girard
:



Mon, 12 Nov 2001 03:00:00 GMT  
 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 ****************************



Wed, 21 Nov 2001 03:00:00 GMT  
 Selecting the last file in a folder.
Hi,
    Thanks for the code!!!

Louis

Quote:

> 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 ****************************



Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Determine Selected Folder and Selected Item in Folder

2. Find the last saved file in a folder and subfolders

3. Search Files and Folders for Last Accessed Date

4. Folder Open Dialog - How to pre-select folder

5. Using Common Dialog control, possible to select folders and their associated files

6. Selecting multiple folders and files in commondialog box

7. Select file and copy to a folder..

8. VBScript in Outlook to select File-System folder

9. Using Commondialog (VB6 Ent) to select a folder - NOT a file

10. Opening a folder and auto-selecting file in it

11. How can i select a file into a folder

12. How to select all files in a folder

 

 
Powered by phpBB® Forum Software