Option Compare Database
Private Sub Command0_Click()
test_errorhandler
End Sub
Public Function test_errorhandler()
Dim db As Database
Dim rst As Recordset
On Error GoTo test_errorhandler_Error
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from table1")
rst.Close
test_errorhandler_Exit:
Exit Function
test_errorhandler_Error:
logfile_handler Err, Err.Description, "test_errorhandler()", CurrentDb.Name
Resume test_errorhandler_Exit
End Function
Public Function logfile_handler(ByVal erNo As Long, ByVal erDesc As String, ByVal procName As String, ByVal dbName As String)
On Error GoTo logfile_handler_Error
Dim Log_file As String
Dim msg As String
Log_file = "Path for file\FileName.txt"
Open Log_file For Append As #1
Print #1, Now()
Print #1, "Database : " & dbName
Print #1, "Procedure: " & procName
Print #1, "Error No.: " & erNo
Print #1, "Desc. : " & erDesc
Print #1, String(40, "=")
Close #1
msg = "Procedure Name: " & procName & "Error : " & erNo & " : " & erDesc
MsgBox msg, , "logfile_handler()"
logfile_handler_Exit:
Exit Function
logfile_handler_Error:
MsgBox Err & " : " & Err.Description, , "logfile_handler()"
Resume logfile_handler_Exit
End Function
VBA Microsoft erişimi kullanarak metin dosyasına hataları yazmak