Not a built function but its easily done using file system object code.
You can also write to a text file
Place the code below in a standard module
Code:
Option Compare Database
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objFso As Object
Dim logStream As Object
Dim fs As Object
'######################################
'# Use this to create and append a text file with log entries
'#
'# Parameters
'# strLogEntry text to write eg "Hello world!"
'# Usage
'# LogEntry " Hello World!"
'#
'# This will create or add to a file with..
'# 25/04/2008 - 10:56:40 : Hello World!
'#
'######################################
Sub LogEntry(strLogEntry As String)
WriteToFile strCurrentDBDir & "LogFile.txt", strLogEntry
'Debug.Print strLogEntry
End Sub
'######################################
'# Use this function to return the current db's path
'#
'######################################
Function strCurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
strCurrentDBDir = left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'######################################
'# Use this to create and append a text file with log entries
'#
'# Parameters
'# strLogFile file to write to eg. "c:\mylog.txt"
'# strLogEntry text to write eg "Hello world!"
'# Usage
'# WriteToFile "c:\mylog.txt", "Hello World!"
'#
'# This will create or add to a file with..
'# 25/04/2008 - 10:56:40 : Hello World!
'#
'######################################
Sub WriteToFile(strLogFile As String, strLogEntry As String)
On Error Resume Next
Set objFso = CreateObject("Scripting.FileSystemObject")
Set logStream = objFso.OpenTextFile(strLogFile, ForAppending, True) 'Open log file
If strLogEntry <> "" Then
logStream.WriteLine Date & " - " & Time() & ": " & strLogEntry
Else
logStream.WriteLine strLogEntry
End If
logStream.Close
End Sub
Sub AddTextToFile(strLogFile As String, strLogEntry As String) 'CR v5253
'Identical to WriteToFile but without the date/time
On Error Resume Next
Set objFso = CreateObject("Scripting.FileSystemObject")
Set logStream = objFso.OpenTextFile(strLogFile, ForAppending, True) 'Open log file
logStream.WriteLine strLogEntry
logStream.Close
End Sub
Function ReadTextFile(strFilename As String) As String
Dim ret As Long
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strFilename) Then
Set logStream = objFso.OpenTextFile(strFilename)
ReadTextFile = logStream.ReadAll
' Debug.Print Mid(ReadTextFile, InStr(ReadTextFile, "Update to version") + 18, 4)
logStream.Close
Set logStream = Nothing
Else
ret = MsgBox("File Not Found", vbCritical)
End If
Set objFso = Nothing
End Function