Error Handling; Allen Browne

N

niuginikiwi

Hi Allen,
I have followed one of your postings here but can not be able to add
any errors to tLogErrors table...
Is there anything else I am missing out. I am using mztools.com to add
in error handling.

Here is the code I am trying out:

Dim lst As ListBox
Dim cbo As ComboBox
Dim iLen As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
Dim strWhere As String
Dim strDoc As String

On Error GoTo Err_Handler
'Purpose:
20 strDoc = "rptOperationSchedule"

30 Set lst = Me.lstPlantings
40 If lst.ItemsSelected.Count > 0 Then
50 strWhere = strWhere & "(PlantingDetailsID" &
MultiSelectSQL(Me.lstPlantings) & ") AND "
60 End If

' Set lst = Me.lstProducts
' If lst.ItemsSelected.Count > 0 Then
' strWhere = strWhere & "(ProductID" &
MultiSelectSQL(Me.lstProducts) & ") AND "
' End If

70 Set cbo = Me.cboOperation
80 If Not IsNull(cbo) Then
90 strWhere = strWhere & "(OperationID = " & cbo.Column(0)
& ") AND "
100 End If

110 If Not IsNull(Me.txtApplicationDate) Then
120 strWhere = strWhere & "([ApplicationDate] = " &
Format(Me.txtApplicationDate, conDateFormat) & ") AND "
130 End If

'Did we get anything?
140 iLen = Len(strWhere) - 5 'Without trailing " AND ".
150 If iLen < 1 Then
160 MsgBox "Sorry! one/more criteria must be supplied",
vbInformation, "Criteria Required"
170 Else
180 strWhere = Left$(strWhere, iLen)

'Use it for this form.
190 Me.Filter = strWhere
200 Me.FilterOn = True


210 If CurrentProject.AllReports(strDoc).IsLoaded Then
220 DoCmd.Close acReport, strDoc
230 End If
240 DoCmd.OpenReport strDoc, acPreview, , strWhere

250 End If
260 Set cbo = Nothing
270 Set lst = Nothing


Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod &
".btnJobSheet_Click")
Resume Exit_Handler

End Sub



What delibrate errors can i cause in there that would be able to
trigger the function you provided at your website to record the error
on to the table.

Thanks,
niuginikiwi
 
A

Allen Browne

Firstly, does the code compile (Compile on Debug menu)?
If so, there's presumably a Private Sub ... line at the top.

To generate an intentional error, add this line between 20 and 30:
25 strDoc = Null
That will fail, since you cannot assign the Null value to a string data
type.

To help with your debugging, you can also add the line:
Stop
to the top of your procedure. When it runs, Access will stop an highlight
this line. Then press F8 repeatedly to step through the code, and trace
where it is going.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

niuginikiwi said:
Hi Allen,
I have followed one of your postings here but can not be able to add
any errors to tLogErrors table...
Is there anything else I am missing out. I am using mztools.com to add
in error handling.

Here is the code I am trying out:

Dim lst As ListBox
Dim cbo As ComboBox
Dim iLen As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
Dim strWhere As String
Dim strDoc As String

On Error GoTo Err_Handler
'Purpose:
20 strDoc = "rptOperationSchedule"

30 Set lst = Me.lstPlantings
40 If lst.ItemsSelected.Count > 0 Then
50 strWhere = strWhere & "(PlantingDetailsID" &
MultiSelectSQL(Me.lstPlantings) & ") AND "
60 End If

' Set lst = Me.lstProducts
' If lst.ItemsSelected.Count > 0 Then
' strWhere = strWhere & "(ProductID" &
MultiSelectSQL(Me.lstProducts) & ") AND "
' End If

70 Set cbo = Me.cboOperation
80 If Not IsNull(cbo) Then
90 strWhere = strWhere & "(OperationID = " & cbo.Column(0)
& ") AND "
100 End If

110 If Not IsNull(Me.txtApplicationDate) Then
120 strWhere = strWhere & "([ApplicationDate] = " &
Format(Me.txtApplicationDate, conDateFormat) & ") AND "
130 End If

'Did we get anything?
140 iLen = Len(strWhere) - 5 'Without trailing " AND ".
150 If iLen < 1 Then
160 MsgBox "Sorry! one/more criteria must be supplied",
vbInformation, "Criteria Required"
170 Else
180 strWhere = Left$(strWhere, iLen)

'Use it for this form.
190 Me.Filter = strWhere
200 Me.FilterOn = True


210 If CurrentProject.AllReports(strDoc).IsLoaded Then
220 DoCmd.Close acReport, strDoc
230 End If
240 DoCmd.OpenReport strDoc, acPreview, , strWhere

250 End If
260 Set cbo = Nothing
270 Set lst = Nothing


Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod &
".btnJobSheet_Click")
Resume Exit_Handler

End Sub



What delibrate errors can i cause in there that would be able to
trigger the function you provided at your website to record the error
on to the table.

Thanks,
niuginikiwi
 
N

niuginikiwi

Thanks Allen,
Yes, it complies okay, and that procedure that I gave above was inside
a private statement so I did as you said to log on an internal error
which is fine ;-)
I am not much of a programmer myself but the F8 thing is quite nice
where I am following how the code is executing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top