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

    OnOpen even cancelled error is persisting after event has failed.

    Hi All,

    I am having a problem with some new filtering code for one of my forms. I am doing two layers of filtering, by In Progress records and then by administrator, and for some reason my standard capture for a user pressing the Cancel button in the Input Box (2nd filter) is causing a really weird error. The code runs for a little while and then I get a msgbox popping up telling me the OpenObject action was canceled. Now if that was the full extent of the issue this wouldn't be such a problem. However, this "OpenObject cancelled" error is now the only response when I click on the button to open the form. I would appreciate anybody's ideas for how I can trap this error and prevent it from wrecking my dBase operation.

    Most of the code involved is in the Form On Open event. However, I will first post the button click event that triggers the opening of the form.

    Button Click (I keep these pretty simple and put all the complex stuff, including error trapping in the On Open event):


    Code:
    Private Sub Change_Requestbtn_Click()
        DoCmd.OpenForm "Change Request Tracker", acNormal
    End Sub
    That's pretty straight forward, I can't see that being where the problem is. However, when your debugger lights up due to some coding problems that is always where it wants to go.

    Alright, here is the code I wrote to allow users to filter the record source by whether a request in In Progress or not and then by which administrator it is assigned to. I suspect this is where my error is but I can't seem to pin it down.
    Code:
    Private Sub Form_Open(Cancel As Integer)
        Dim strCA As String, strSQL As String, strWHERE As String, strAND, Msg, Title, Style, Response
        On Error GoTo ErrHandler
        
        strSQL = "SELECT CRTracker.*" & _
        "FROM PartInfo INNER JOIN CRTracker ON PartInfo.[Smart Id] = CRTracker.[SMART ID]"
    
     ' Determining if the user wants to view historical or only active requests
            Msg = "View Only Requests In Progress?"    ' Define message.
             Style = vbYesNo + vbQuestion + vbDefaultButton2    ' Define buttons.
             Title = "Which Records to View?"    ' Define title.
             ' Display message.
             Response = MsgBox(Msg, Style, Title)
            If Response = vbYes Then    ' User chose Yes.
               strWHERE = " WHERE CRTracker.[Request In Progress?] Like 'Yes'"
    Repeat:
                    strCA = InputBox("Enter the CA for the paricipants you wish to view" & vbCr & vbCr & _
                            Chr(9) & "VP, LM, KR, SH, or JS" & vbCr  & "Or press * to view all participants", "Show All/Filter")
                            
                   Select Case strCA
                    Case "VP"
                        strAND = " AND PartInfo.CA Like 'VP';"
    
                    Case "LM"
                        strAND = " AND PartInfo.CA Like 'LM';"
                        
                    Case "KR"
                        strAND = " AND PartInfo.CA Like 'KR';"
                        
                    Case "SH"
                        strAND = " AND PartInfo.CA Like 'SH';"
                        
                    Case "JS"
                        strAND = " AND PartInfo.CA Like 'JS';"
                        
                    Case "*"
                        strAND = ";"
                    Case ""
                        GoTo MyExit
                    Case Else
                        MsgBox "I'm sorry I must have misheard you.  Could  you please enter your selection again?", vbOKOnly, "My Mistake"
                        GoTo Repeat
                    End Select
    
             Else    ' User chose No.
    Repeat2:
                    strCA = InputBox("Enter the CA for the paricipants you wish to view" & vbCr & vbCr & _
                            Chr(9) & "VP, LM, KR, SH, or JS" & vbCr  & "Or press * to view all participants", "Show All/Filter")
                            
                   Select Case strCA
                    Case "VP"
                        strWHERE = " WHERE PartInfo.CA Like 'VP';"
                        strAND = ""
                    Case "LM"
                        strWHERE = " WHERE PartInfo.CA Like 'LM';"
                        strAND = ""
                    Case "KR"
                        strWHERE = " WHERE PartInfo.CA Like 'KR';"
                        strAND = ""
                    Case "SH"
                        strWHERE = " WHERE PartInfo.CA Like 'SH';"
                        strAND = ""
                    Case "JS"
                        strWHERE = " WHERE PartInfo.CA Like 'JS';"
                        strAND = ""
                    Case "*"
                        strWHERE = ";"
                        strAND = ""
                    Case ""
                        GoTo MyExit
                    Case Else
                        MsgBox "I'm sorry I must have misheard you.  Could  you please enter your selection again?", vbOKOnly, "My Mistake"
                        GoTo Repeat2
                    End Select
             End If
    MyExit:
        Cancel = True
        ' Setting Form record source based on above selections
        Me.RecordSource = strSQL & strWHERE & strAND
        Exit Sub
    ErrHandler:
        If Err.Number = 2501 Then
            MsgBox "No Selection Made - Form Open canceled", , "Form Open Canceled"
        Else
            MsgBox Err.Number & ": " & Err.Description
        End If
    End Sub
    Ssnafu, you might find something familiar about that MsgBox code. Thanks again for the help earlier!

    So....there it is. If anyone has any ideas what could be screwing me up I would greatly appreciate it.

    Thanks!

  2. #2
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164
    Oddly enough, after shutting down, compacting and repair, now clicking the button allows me to go through both filtering steps but the code ends with an "Error 2501: OpenObject cancelled" error.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I suspect that the problem, here, is that the Form_Open event is too early to be trying to do this sort of thing! Try moving your code to the Form_Load event, instead, and see what happens. Remember to delete it from the Form_Open!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 3
    Last Post: 05-06-2012, 06:29 PM
  2. Error When Event is Cancelled
    By tylerg11 in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 09:48 AM
  3. ODBC -- Call Failed error
    By Coffee in forum Access
    Replies: 3
    Last Post: 07-08-2011, 10:34 AM
  4. Action Failed -Error Number: 2950
    By Cindy in forum Access
    Replies: 5
    Last Post: 07-07-2010, 11:51 AM
  5. Replies: 2
    Last Post: 11-02-2009, 10:14 PM

Tags for this Thread

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