Hi, I'm looking for some advice on cornering an annoying bug I cannot recreate! I'll just paste the code here:
Sometimes I get the first error message (Error creating view) in my log. Err.Number and Err.Description is empty and nDebugStep = 1.
Does this mean the error occurs in LoadViewByDate? How come the outer error handler catches it? Help me please!
graabein
Code:
Public Sub CreateView( _
lv As ListView, _
lvTemp As ListView, _
dtFromDate As Date, _
dtToDate As Date, _
Optional sFilter As String = "" _
)
Dim rs As New ADODB.Recordset
Dim nDebugStep As Integer
On Error GoTo error_handler
nDebugStep = 1
If LoadViewByDate(dtFromDate, dtToDate, sFilter, rs) Then
nDebugStep = 2
'...snip...
End If
nDebugStep = -1
CloseAndUnloadRecordset rs
db.CloseConn
Exit Sub
error_handler:
CloseRecordsetAndConnection rs, db
lv.Visible = True
LogError "Error creating view.", _
CStr(nDebugStep) & " Filter[" & sFilter & _
"] FromDate[" & FormattedDate(dtFromDate) & _
"] ToDate[" & FormattedDate(dtToDate) & "]", & _
Err.Number, Err.Description
End Sub
Private Function LoadViewByDate( _
dtFromDate As Date, _
dtToDate As Date, _
sFilter As String, _
ByRef rs As ADODB.Recordset _
) As Boolean
Dim cmd As ADODB.Command
On Error GoTo LoadViewByDate_Error
LoadViewByDate = False
dtFromDate = DateOnly(dtFromDate)
dtToDate = DateOnly(dtToDate)
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = db.Conn
.CommandType = adCmdStoredProc
.CommandText = "usp_ViewByDate"
.Parameters.Append .CreateParameter("@UserID", adInteger, , , g_UserID)
.Parameters.Append .CreateParameter("@UnitID", adInteger, , , g_UnitID)
.Parameters.Append .CreateParameter("@FromDate", adDate, , , dtFromDate)
.Parameters.Append .CreateParameter("@ToDate", adDate, , , dtToDate)
.Parameters.Append .CreateParameter("@Filter", adVarChar, , 10, sFilter)
End With
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenDynamic, adLockReadOnly
If IsRecordsetOpen(rs) Then
LoadViewByDate = True
End If
Set cmd = Nothing
Exit Function
LoadViewByDate_Error:
LogError "Error loading view from database.", _
"UserID [" & g_UserID & "] UnitID [" & UnitID & _
"] FromDate [" & FormattedDate(dtFromDate) & _
"] ToDate [" & FormattedDate(dtToDate) & _
"] Filter [" & sFilter & "]", & _
Err.Number, Err.Description
End Function
Sometimes I get the first error message (Error creating view) in my log. Err.Number and Err.Description is empty and nDebugStep = 1.
Does this mean the error occurs in LoadViewByDate? How come the outer error handler catches it? Help me please!
graabein