You can use something like this (write in Append mode so you don't loose previous entries):
VB Code:
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. On Error GoTo ErrorHandeler
  5.     Debug.Print 1 / 0
  6.         Exit Sub
  7. ErrorHandeler:
  8.     writeLog Err.number, Err.description, "Form1 Form_Load"
  9. End Sub
  10.  
  11. 'in module
  12. Public Sub writeLog(number As Long, description As String, procedure As String)
  13.     Dim ff As Integer: ff = FreeFile
  14.         Open App.Path & "\error.log" For Append As #ff
  15.             Print #ff, Format(Date, "dd.mm.yy") & ", " & Format(Time, "hh:mm:ss") & " - error #" & number & " - " & description & " - " & "in " & procedure & " procedure"
  16.         Close #ff
  17. End Sub