Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

updating dates of saved files

4 views
Skip to first unread message

Denise Pollock

unread,
Jul 25, 2007, 6:22:02 PM7/25/07
to
Is it possible to make a VB code that can find the date modified on a
specific file saved on my network? If so how would I go about doing it? I
basically need a list of all the files in a particular folder and the date
they were last modified. So I can make other queries based on the dates.

Thanks,

Denise

James A. Fortune

unread,
Jul 25, 2007, 8:08:23 PM7/25/07
to

The FileDateTime function should get you that information.

Here's some code I use to choose a directory and place it into a textbox:

'---begin Code behind form---
Private Sub cmdGetPath_Click()
'Opens a Treeview control that displays the directories in a computer

Dim lpIDList As Long
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "This is the title"
With tBrowseInfo
.hWndOwner = Me.hwnd
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
If Right(sBuffer, 1) <> "\" Then sBuffer = sBuffer & "\"
txtSaveFileDirectory.Value = sBuffer
End If
End Sub
'----end Code behind form----

'---begin Module code---
'----Code from http://support.microsoft.com/kb/179497
Public Const BIF_RETURNONLYFSDIRS = 1
Public Const BIF_DONTGOBELOWDOMAIN = 2
Public Const MAX_PATH = 260

Public Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Public Declare Function SHBrowseForFolder Lib "shell32" _
(lpbi As BrowseInfo) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidList As Long, _
ByVal lpBuffer As String) As Long

Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, ByVal _
lpString2 As String) As Long
'----end Module code----

Once you have the directory you can use the Dir() function to get the
names of all the files in the directory. After that, you have what you
need to run the FileDateTime function on all the files in the directory.

James A. Fortune
MPAP...@FortuneJames.com

Denise Pollock

unread,
Aug 1, 2007, 2:02:02 PM8/1/07
to
I would love to try this out. unfortunately I can't seem to get to the form
in VB. I have not done anything to hide the codes, and I was able to create
a module easily enough. But I can't seem to get the form to show up when I
open the VB editor. Also does the behind the form code need to be entered
for each file I want to update the date for?

Thanks,

James A. Fortune

unread,
Aug 1, 2007, 7:51:45 PM8/1/07
to
Denise Pollock wrote:
> I would love to try this out. unfortunately I can't seem to get to the form
> in VB. I have not done anything to hide the codes, and I was able to create
> a module easily enough. But I can't seem to get the form to show up when I
> open the VB editor. Also does the behind the form code need to be entered
> for each file I want to update the date for?
>
> Thanks,

To get to the code behind a form, single click on the form's name and
click 'Design.' Next select View...Code. You only need to put the code
in once, but don't paste the code in yet. Unlike module code, Access
sometimes doesn't attach pasted form code to the buttons correctly. You
need to go back to the form design and create a command button called
'cmdGetPath' and a textbox called 'txtSaveFileDirectory' first. Double
click cmdGetPath, select the 'Event' tab, click in the white rectangle
to the right of the 'On Click' event, then click on the three dots to
the far right. In the box that says 'Choose Builder,' double click
'Code Builder' or select 'Code Builder' and click 'OK.' That is where
to paste the code behind form.

I'll look around to see if I have an example of pulling all the files
from a directory for you to look at. The FileDateTime can be called in
a loop by exploiting the behavior of the Dir() function when called
multiple times.

James A. Fortune
MPAP...@FortuneJames.com

James A. Fortune

unread,
Aug 1, 2007, 10:37:33 PM8/1/07
to
James A. Fortune wrote:

> I'll look around to see if I have an example of pulling all the files
> from a directory for you to look at. The FileDateTime can be called in
> a loop by exploiting the behavior of the Dir() function when called
> multiple times.

I placed a sample A97 database at:

http://personalwebs.oakland.edu/~fortune/FileTimes.zip

It worked on a directory containing over 12,000 files.

James A. Fortune
MPAP...@FortuneJames.com

Denise Pollock

unread,
Aug 3, 2007, 4:14:00 PM8/3/07
to
I like that, but it doesn't do what I need it to do. I am always going to be
using the same network directory, and having to choose which one defeats the
purpose slightly. Instead of returning a list, I need it to populate fields.
Is there a way to do this so I can have a field for the file name, and a
field for the date and the command button would update them? I need to be
able to run queries against the information so I can find out what files have
or have not been updated. perhaps something that would delete old data and
create all new records with the new data. Or just update the dates for the
files currently listed in the database.

James A. Fortune

unread,
Aug 3, 2007, 4:24:46 PM8/3/07
to
Denise Pollock wrote:
> I like that, but it doesn't do what I need it to do. I am always going to be
> using the same network directory, and having to choose which one defeats the
> purpose slightly. Instead of returning a list, I need it to populate fields.
> Is there a way to do this so I can have a field for the file name, and a
> field for the date and the command button would update them? I need to be
> able to run queries against the information so I can find out what files have
> or have not been updated. perhaps something that would delete old data and
> create all new records with the new data. Or just update the dates for the
> files currently listed in the database.

In the Form_Open event, put the name of the hard-coded directory into
the textbox. Afterwards, in the same event, copy the code after the
directory is selected from cmdGetPath. Then delete cmdGetpath's code
and the command button. You can skip adding the information to the
listbox. The table should refresh each time the form is opened. Post
back if you need help with any of that.

James A. Fortune
MPAP...@FortuneJames.com

James A. Fortune

unread,
Aug 20, 2007, 5:27:06 PM8/20/07
to
Denise Pollock wrote:
> I tried to do that but I'm really clueless about VB so I am sure I did not do
> it correctly. Can you maybe give step by step instructions or lead me to
> some? Do I need to start with the files already listed in the form? Or will
> this code be able to pull in the files into one field, and the date into the
> other?
>
> Sorry for the delay in responding, I am only working on this project when
> there is nothing else pressing and its been a busy couple of weeks.
>
> Thanks,
>
> Denise

I placed a hardcoded version at:

http://personalwebs.oakland.edu/~fortune/FileTimesHardCoded.zip

After converting it, hold down the shift key while opening it and change
the first line of Form_Load,

txtSaveFileDirectory.Value = "T:\Databases\"

to

txtSaveFileDirectory.Value = "YourNetworkDriveLetter:\YourNetworkPath\"

Once the database/form is opened, tblFiles will contain the filenames in
a field called FileName and the file creation/modification dates
(including time) in a field called FileDate.

James A. Fortune
MPAP...@FortuneJames.com

Denise Pollock

unread,
Aug 21, 2007, 1:18:05 PM8/21/07
to
Well I was able to change the path and the path shows up in the form view.
But the data it is pulling is from the My Documents folder, and if I don't
put the \ on the end it pulls up all the files on my Desktop. I don't
actually have a drive letter for the server. I tried to map to it and just
try putting "Y:\" as the path and it still showed files in My Documents.

Is there something else I need to change?

James A. Fortune

unread,
Aug 23, 2007, 3:31:47 PM8/23/07
to
Denise Pollock wrote:
> Well I was able to change the path and the path shows up in the form view.
> But the data it is pulling is from the My Documents folder, and if I don't
> put the \ on the end it pulls up all the files on my Desktop. I don't
> actually have a drive letter for the server. I tried to map to it and just
> try putting "Y:\" as the path and it still showed files in My Documents.
>
> Is there something else I need to change?

As a matter of fact, there is. In addition to the line
'txtSaveFileDirectory = "T:\Databases\"' add another line after that one
that says:

sBuffer = txtSaveFileDirectory.Value

sBuffer was a string that got filled by the treeview and needs to be set
to the hard-coded value. I'll try to update the file in the link today
also. It should also work with UNC paths. Thanks for catching that.

James A. Fortune
MPAP...@FortuneJames.com

Denise Pollock

unread,
Aug 23, 2007, 4:02:00 PM8/23/07
to
Thanks it is working now. Thank you so much for your help.
0 new messages