Checking Last Modified Date

  • Thread starter Gordon Bentley-Mix on news.microsoft.com
  • Start date
G

Gordon Bentley-Mix on news.microsoft.com

With the help of Greg Maxey, I'm working on a process to use an external data
source (a Word doc) to populate several ComboBoxes in a UserForm. The process
builds on the method described in
http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm, but loads the data
from the source into document variables before the UserForm is displayed and
uses these values to populate the ComboBoxes. (This stops the UserForm from
flickering when the source document is opened and closed - a real issue if
there are multiple ComboBoxes being populated.) All of this works great
(Thanks Greg!), but I want to take it one step further.

My templates contain functionality that allows the user to re-run the code
to modify the document after it's created. However, because the values for
populating the ComboBoxes already exist as document variables in the
document, it would be better if these values were reused. I can do this by
checking to see if the document is a new document or one that's being re-run.
If it's a re-run then I just use the values that are cached in the document
variables.

Unfortunately, this process doesn't take into account possible changes to
the data source since the document was intially created. I've found a way to
accomodate this by storing the last modified date of the data source used to
create the document in a document variable and checking this value against
the last modified date of the current data source.

However, this process requires the data source to be opened (to access the
"date last modified" built-in document property), and if the data source is
already open, there's really no advantage in not using it. What I'd really
like to do is check the last modified date *without* opening the data source.
I reckon this must be possible because Windows Exploder shows this date on
the properties sheet (and even when just hovering over the file). So how do I
get there from here?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
G

Greg Maxey

Gordon,

Sub ScratchMacro()
Dim pFile As String
pFile = "C:\Test File.docm"
MsgBox GetLastModDate(pFile)
End Sub

Function GetLastModDate(ByRef pStr As String) As String
On Error GoTo Err_Handler
GetLastModDate = pStr & "' was created or last " & _
"modified on " & FileDateTime(pStr) & "."
Exit Function
Err_Handler:
Select Case Err.Number
Case 53
GetLastModDate = "Can't find file '" & pStr & "'. " & _
"Check the file path and try again."
Case Else
GetLastModDate "Error number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description
End Select
End Function

Of course this means you have to share your finished product ;-)
 
G

Gordon Bentley-Mix on news.microsoft.com

Legend mate! Looks like it's going to work. (It was the FileDateTime function
that I needed.) I'll defintely share - after I do a substantial bit of clean
up. ;-P
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top