displaying date modified from windows explorer

binghamw

BingleyW
Local time
Today, 14:05
Joined
Apr 22, 2004
Messages
57
Hi,

I have set up a little program where you can browse to a specific file and the file and pathname are displayed in the textbox "txtFile".
I then would like a textbox where the "date modified" of that particular file (from Windows Explorer) is displayed by clicking on a button called "cmdFiledate".

I have the following code on the On_Click Event of button "cmdFiledate":

Private Sub cmdFileDate_Click()

'Code adapted from
'Microsoft Knowledge Base Article - 186118
'HOWTO: Use FileSystemObject with Visual Basic
'http://support.microsoft.com/default.aspx?scid=kb;en-us;186118

If CheckChoice(True) Then
Exit Sub
End If

Dim myFileSystem As New FileSystemObject
Dim myFile As File

FilePath = Me.txtFile

Set myFile = myFileSystem.GetOpenFileName(txtFile)

MsgBox "Date Last Modified : " & myFile.DateLastModified & vbNewLine


Set myFile = Nothing
Set myFileSystem = Nothing

End Sub

It keeps getting stuck on the line:
Dim myFileSystem As New FileSystemObject

Also, the way that code was run was that the file path was displayed in one text box, and the actual file name was stored in a list box. I have the file name and pathname displayed in only a textbox (txtFile).

Does anyone know what is wrong with the code?

Thanks,
Binger
 
Why not use the built-in VBA FileDateTime() function to extract the date/time the file was created or last modified?

MsgBox FileDateTime("X:\Testing\YourFile.txt")

HTH
 

Users who are viewing this thread

Back
Top Bottom