Results 1 to 4 of 4
  1. #1
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164

    Canceling a report filter without Run-time error

    Hello Everyone,

    So here's my problem. I have a form and report that are used by multiple coworkers who all track specific issues with specifically assigned customers. Each customer has, as part of their record, their assigned administrator and I've got some simple code that allows each administrator to filter the records present in either the form or the report to just their customers. It works beautifully and I am very happy with it, unless users decide they don't want to look at that form or report. If a user does not enter anything or presses the Cancel button on the InputBox, they get a run-time error '2501'. Can I simply have the result be that the form/report does not open?



    The code for this feature in the form is shown below (the code is pretty much the same in the report except for a much longer SQL statement):
    Code:
    Private Sub Form_Open(Cancel As Integer)
        Dim strCA As String, strSQL As String, strWHERE As String
        On Error GoTo ErrHandler
        strSQL = "SELECT * FROM GandHTracker"
        
        strCA = InputBox("Enter the CA for the paricipants you wish to view" & vbCr & vbCr & _
                "VP, LM, KR, SH, or JS" & vbCr & "Or press * to view all participants", "Show All/Filter")
                
        If strCA = "" Then
            Cancel = True
        ElseIf strCA = "*" Then
            Me.RecordSource = strSQL
        Else
            strWHERE = " WHERE CA Like '" & strCA & "';"
            Debug.Print strSQL
            Debug.Print strWHERE
            Me.RecordSource = strSQL & strWHERE
        End If
        Exit Sub
    ErrHandler:
        MsgBox Err.Number & ":  " & Err.Description
    End Sub
    Any thoughts/suggestions would be appreciated. Thanks!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I would assume that the form is being opened from some other code, like the On Click event of a button. If this is true, then the error message will be generated in the error handling code of that button. So you could deal with it there.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    The attached db shows how to handle the error.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164
    Thanks! I tweaked the code a little to provide a message box notifying the user that no valid selection was made. It works perfectly.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Run Time Error 2465 In Report
    By desk4tbc in forum Programming
    Replies: 9
    Last Post: 09-06-2011, 08:00 PM
  2. Replies: 7
    Last Post: 08-04-2011, 07:49 PM
  3. Replies: 1
    Last Post: 08-01-2011, 04:17 PM
  4. Filter Report by Time
    By Tyork in forum Reports
    Replies: 4
    Last Post: 11-11-2010, 01:17 PM
  5. Replies: 1
    Last Post: 12-09-2005, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums