Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Stamp Problem....Can;t get the module to work!!!

Status
Not open for further replies.

mbarnett

MIS
Jun 15, 2003
123
US
Hi All,

I'm trying to get the TimeStamp of Files I'm importing into my Table tblFileNames...In the table I have the path and File name in the third column I want to know the Time Stamp of each file. I tried the below function, but I keep getting an error message...I would appreciate your help -

Private Sub Form_MyTimeLoad()

Dim db As Database
Dim rst As Variant
Dim NewFile As Variant

DoCmd.Hourglass True
DoCmd.SetWarnings False

Set db = CurrentDb
Set rst = db.TableDefs("TblFileNames").OpenRecordset(dbOpenTable)
rst.MoveFirst
Do Until rst.EOF

NewFile = SaveFileDetails(rst("ImportPath"), rst("ImportName"))

rst.Edit
rst("RunTime") = FileDateTime(rst("ImportPath") & rst("ImportName"))
rst.Update
rst.MoveNext
Loop
DoCmd.Hourglass False
DoCmd.SetWarnings True
End Sub
Function SaveFileDetails(strFilePath As Variant, strFileName As Variant)
'Pass the path to the file, as well as the
'file name, to this function

Dim strFileDate As String
Dim strSQL As String

If strFileName = "" Then
Exit Function
End If

'Get the file date and time
strFileDate = FileDateTime(strFilePath & strFileName)

'Format the date as required for your table
strFileDate = Format$(strFileDate, "dd/mm/yyyy")

strSQL = "INSERT INTO tblFileNames.[Run Time]"
strSQL = strSQL & " VALUES ('" & strFileName & "', '"
strSQL = strSQL & strFileDate & "')"

DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)

End Function
 
I would guess the problem comes here:
Code:
strSQL = "INSERT INTO tblFileNames.[Run Time]"
strSQL = strSQL & " VALUES ('" & strFileName & "', '"
strSQL = strSQL & strFileDate & "')"
It would appear that you are trying to put two values (seperated by the ",") into one field "Run Time".
Try something like:
Code:
strFileName = strFileName & " " & strFileDate

"INSERT INTO tblFileNames.[Run Time]"
strSQL = strSQL & " VALUES ('" & strFileName & "')"

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Sorry, in my post the line
Code:
"INSERT INTO tblFileNames.[Run Time]"
should read
Code:
strSQL = "INSERT INTO tblFileNames.[Run Time]"

Harleyquinn

---------------------------------
For tsunami relief donations
 
Hi Harleyquinn,

Still getting error - Run-Time error'3024':

Could not find fil 'Y:\db\tblFileNames.mdb'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top