Results 1 to 7 of 7
  1. #1
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12

    Suppress a openform action has been cancelled dialog message - not on error

    Hi world,

    From a search style form, clicking search button starts my query which opens my query results form. If there are no records found from the search I have some code that during the 'on open' event of results form, opens a yes no message box. - "No clients found, would you like to add a new client?"

    Clicking Yes takes user to 'new client form'
    Clicking No cancels the openform event and takes user back to search form.

    This all works fine, but what also happens is there is a 2501 dialog message "An openform action has been cancelled" that also pops up as a result of clicking no and cancelling the form opening action.

    How can I supress this, bearing in mind its not triggering from an error?

    I have tried various methods and not got one working. Maybe because I did it wrong... Not sure.
    Have tried adding a doCmd.SetWarnings (True/False/WarningsOn/WarningsOff)...
    Have tried adding On Error Resume Next
    Have also tried an error handler, similar to from here....
    http://answers.microsoft.com/en-us/o...5-009e2ee88050



    Here is my "On Open" code.....
    Code:
    Option Compare Database
    
    Private Sub Form_Open(cancel As Integer)
        
        Dim intAnswer As Integer
                    
        If Me.Recordset.RecordCount = 0 Then                         'If there are no records found, open YesNo box -
            Select Case MsgBox("Do you want to add a new Client?", vbQuestion + vbYesNo, "No clients found")
                Case vbYes                                                       'When users click yes....
                Dim stDocName As String
                stDocName = "FrmNewClient"
                    DoCmd.OpenForm "FrmNewClient"               'Open new client form
                    DoCmd.OpenForm stDocName, , , acFormAdd         'open as new record
                    DoCmd.Close acForm, Me.Name                             'Close search form
                Case vbNo                                             'when users click no....
                    cancel = True                                    'Stop trying to load the form
                    DoCmd.OpenForm "SearchF"                                  'Go back to search form
            End Select
        End If
    End Sub
    Any help would be splendid.
    Jamie.

  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
    Put some Error Handling code in the sub that opens the form, to catch error 2501.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I suspect you need to trap for 2501 in the code that opens this form:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12
    pbaldy, Thats precisely the web page I found and the code I tried. I must be placing the code in the wrong place/s then maybe? I put the 'On Error' at the top under the Dim. The ExitHandler after the End If and the ErrorHandler after that. The message still came up.... ?

    Is this an error though, or is it an 'action dialog' ? (If thats right? - Still learning)

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you miss

    Quote Originally Posted by pbaldy View Post
    I suspect you need to trap for 2501 in the code that opens this form:
    In other words, not in this form but the other.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12
    Quote Originally Posted by pbaldy View Post
    In other words, not in this form but the other.
    Of course! Because it was the form/command button that called the open form action causing it in the first place! D'oh! You are a star! Thanks very much, and thanks for the code from your web page. I'm still getting to grips with error handling and thats a good lesson for me.

    Cheers again.
    Jamie.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2013, 01:56 PM
  2. runtime error 2501 openform action was canceled
    By rumenrs in forum Programming
    Replies: 2
    Last Post: 04-11-2013, 04:29 AM
  3. Replies: 3
    Last Post: 05-06-2012, 06:29 PM
  4. Replies: 1
    Last Post: 03-25-2012, 01:53 PM
  5. Suppress spell check error message
    By sabre1 in forum Forms
    Replies: 1
    Last Post: 03-24-2011, 09:58 AM

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