"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
"Justin Hoffman" <j@b.com> wrote in message
news:db**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi Keith
I can't see the error handling in the other procedure - but there is no
point looking for 2501 in two places. Here is a typical example where a
command button opens a report. There is no error handling in the NoData
event - you could put some in - but the place to catch 2501 is in the
preview button's OnClick event.
Thanks Justin. Trapping in more that one place was an act of desperation
;-p
This is what I have in the command button Click event:
****
Private Sub cmdPreview_Click()
On Error GoTo err_trap
Dim strCriteria As String
strCriteria = Me.OpenArgs & " = '" & Me.cboActionee & "'"
If Me.ogrClosed <> 3 Then strCriteria = strCriteria & " And [Closed] = " &
Me.ogrClosed
Me.Visible = False
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview, ,
strCriteria
DoCmd.Maximize
err_trap:
If Err.Number = 2501 Then Exit Sub
End Sub
****
I'll try your version in the meantime, but I'm wondering if some of the
other stuff I'm doing is upsetting Access. I'm basically using the same
filter form for two different reports. I'm using OpenArgs to pass the
name of the field to filter on.
Regards,
Keith.
I can't see why this would not prevent the error 2501 occuring. Normally I
have two labels Err_Handler and Exit_Handler so that the error handling code
only runs if there was an error - whereas yours will always check if the
error number is 2501 - even if no error occurred.
The Exit_Handler label always has an exit sub as the last line and it
enables me to clean up - often with an On Error Resume Next line at the
beginning of the block. You may have your own style you are happy with, but
you might like to consider the sort of approach shown below.
The only other comment I would make is that you could slow down with the
code a bit. For example:
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview
I might take the time to dim a variable for the report name and make sure I
get a non-zero length string before I try to open the report, but I guess
you will say that you can guarantee that gcFrmPrint will be open and
lstReport.Column(1) will return a valid non-null value.
Private Sub ShowRecordCount()
On Error GoTo Err_Handler
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "SELECT COUNT(*) AS MyCount FROM tblMyTable"
Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
If Not rst.EOF Then
MsgBox rst.Fields("MyCount") & " record(s)"
End If
Exit_Handler:
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub