benim standart hata işleyicisi kullanarak döngüler yüzden sorunu bulmak için bir yol var benim kodunda her döngü yapısı için özel hata işleyicileri zanaat istemiyorum elimden böylece daha sonra onlar için özel bir hata işleyici yazınız.
Bir döngüde bir hata oluşursa, normalde hatadan neyin neden geçtiğini bilmek istiyorum. Bu hataları öğrenmek için, birçok insanın yaptığı gibi bir günlük dosyasına hata mesajları yazarım. Ancak, bir döngüde hata oluşursa, döngü yinelendiğinde ve 80 000 yinelemede yaygın olmayan bir hata olduğunda, bir günlük dosyasına yazma tehlikelidir.Bu nedenle, aynı hataları algılayan ve bunları hata günlüğüne yazmayı atlayan hata kayıt fonksiyonuma bazı kodlar koydum.
Her yordamda kullanılan standart hata işleyicim buna benzer. Hata türünü kaydeder, meydana gelen hatayı ve alınan prosedürün herhangi bir parametresini (bu durumda FileType) kaydeder.
procerr:
Call NewErrorLog(Err.number, Err.Description, "GetOutputFileType", FileType)
Resume exitproc
Tabloya yazdığım (ms-giriş halindeyim) hata günlükleme işlevim aşağıdaki gibidir. Önceki hata değerlerini korumak ve mevcut sürümlerle karşılaştırmak için statik değişkenler kullanır. İlk hata günlüğe kaydedilir, daha sonra ikinci özdeş hata, kullanıcı olduğumda veya diğer kullanıcı modunda ise uygulamayı sonlandırırsa hata ayıklama moduna iter. Bir hata logger olduğunu
Public Function NewErrorLog(ErrCode As Variant, ErrDesc As Variant, Optional Source As Variant = "", Optional ErrData As Variant = Null) As Boolean
On Error GoTo errLogError
'Records errors from application code
Dim dbs As Database
Dim rst As Recordset
Dim ErrorLogID As Long
Dim StackInfo As String
Dim MustQuit As Boolean
Dim i As Long
Static ErrCodeOld As Long
Static SourceOld As String
Static ErrDataOld As String
'Detects errors that occur in loops and records only the first two.
If Nz(ErrCode, 0) = ErrCodeOld And Nz(Source, "") = SourceOld And Nz(ErrData, "") = ErrDataOld Then
NewErrorLog = True
MsgBox "Error has occured in a loop: " & Nz(ErrCode, 0) & Space(1) & Nz(ErrDesc, "") & ": " & Nz(Source, "") & "[" & Nz(ErrData, "") & "]", vbExclamation, Appname
If Not gDeveloping Then 'Allow debugging
Stop
Exit Function
Else
ErrDesc = "[loop]" & Nz(ErrDesc, "") 'Flag this error as coming from a loop
MsgBox "Error has been logged, now Quiting", vbInformation, Appname
MustQuit = True 'will Quit after error has been logged
End If
Else
'Save current values to static variables
ErrCodeOld = Nz(ErrCode, 0)
SourceOld = Nz(Source, "")
ErrDataOld = Nz(ErrData, "")
End If
'From FMS tools pushstack/popstack - tells me the names of the calling procedures
For i = 1 To UBound(mCallStack)
If Len(mCallStack(i)) > 0 Then StackInfo = StackInfo & "\" & mCallStack(i)
Next
'Open error table
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tbl_ErrLog", dbOpenTable)
'Write the error to the error table
With rst
.AddNew
!ErrSource = Source
!ErrTime = Now()
!ErrCode = ErrCode
!ErrDesc = ErrDesc
!ErrData = ErrData
!StackTrace = StackInfo
.Update
.BookMark = .LastModified
ErrorLogID = !ErrLogID
End With
rst.Close: Set rst = Nothing
dbs.Close: Set dbs = Nothing
DoCmd.Hourglass False
DoCmd.Echo True
DoEvents
If MustQuit = True Then DoCmd.Quit
exitLogError:
Exit Function
errLogError:
MsgBox "An error occured whilst logging the details of another error " & vbNewLine & _
"Send details to Developer: " & Err.number & ", " & Err.Description, vbCritical, "Please e-mail this message to developer"
Resume exitLogError
End Function
Not incelikle hata logları hataları işleyemez uygulama olarak uygulamanızda en mermi geçirmez fonksiyonu olmak. Bu nedenle, null'ların gizlice giremediğinden emin olmak için NZ() kullanıyorum. Ayrıca, hata işlemindeki döngülere bakmayı bildiğimden, ikinci özdeş hataya [döngü] eklediğimi unutmayın.
sorgu tabloları olmayan 'liste nesneleri' yok mu? Sorgu tablosuna sahip olmak için sayfaya ihtiyacım var. –
@Justin, eğer öyleyse, 'ListObjects (1) .QueryTable Is Nothing' için bir sınama ekleyin - kodunuzda bu sınama yoktu. Örneğimin ana noktası, ListObjects koleksiyonunun ilk unsuru iptal etmeden önce herhangi bir unsuru olup olmadığını kontrol etmektir. – Joe