What event fires after form is displayed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • glinkoswald
    New Member
    • Jul 2013
    • 8

    What event fires after form is displayed

    I've been through:
    Open → Load → Resize → Activate → Current

    but each of these seems to occur before the form is actually displayed on the screen. I even tried GotFocus.

    I have a msgbox that is supposed to display after the form is displayed, but it actually shows up before the form displays and stops it from being displayed until the user clicks OK.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    -Order of events
    Order of events for database objects (v2010)

    Comment

    • glinkoswald
      New Member
      • Jul 2013
      • 8

      #3
      Thanks, zmbd, you'll see that in my post I actually cut-and-paste from that very page. Current and GotFocus occur before the form is displayed.

      Or are you trying to tell me that there are no more events after that, and I'm just out of luck?
      Last edited by glinkoswald; Jul 29 '13, 05:24 PM. Reason: additional question added.

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        You could use the form's Timer event to display your message box after a short interval. Try setting the TimerInterval property to, say, between 500 and 1000 (that is, between 0.5s and 1s), then place the code for your message box etc in the On Timer event sub (as in the example below).

        Code:
        Private Sub Form_Timer()
            MsgBox "This Is A Timer Event", vbOKOnly
            Me.TimerInterval = 0
        End Sub
        Setting the TimerInterval property to 0 in the timer event sub effectively cancels the timer after the first run, so the message box will display just once each time the form is opened. However, such behaviour can be very annoying to users unless you record the message state somewhere and act on it accordingly (say, by using a custom form instead of a message box, with the form containing a tick box for 'don't show this message again'). You can, for example, use the On Load event to test the state of whatever you have stored and set the Me.TimerInterva l property to 0 again if you don't want your On Timer code to run.

        -Stewart
        Last edited by Stewart Ross; Jul 29 '13, 06:52 PM.

        Comment

        • glinkoswald
          New Member
          • Jul 2013
          • 8

          #5
          Just saw your paragraph and see what you were trying to do. I'd tried the timer earlier and got caught in the loop. Will try inserting the timer interval change in there.
          Last edited by glinkoswald; Jul 29 '13, 08:11 PM. Reason: Oopsies.

          Comment

          • glinkoswald
            New Member
            • Jul 2013
            • 8

            #6
            Stewart, that accomplished it.

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              Please post your entire code that has the message you wish to display in it - please include from "sub * () ... end sub"

              Please, remember to use the code format button [CODE/]

              Comment

              • glinkoswald
                New Member
                • Jul 2013
                • 8

                #8
                zmbd, in the On Timer event for the form, I have following Event Procedure:

                Code:
                Private Sub Form_Timer()
                 
                Dim strOutputPath As String
                strOutputPath = DLookup("SavePath", "tblGlobalParams", "ID=1")
                If Not FileExists(strOutputPath, True) Then
                  MsgBox "Caution: Save location is not valid." & vbCrLf & vbCrLf & _
                          "Use 'Reset Global Settings' to set valid path."
                End If
                  Me.TimerInterval = 0
                End Sub
                Timer Interval for the form is set to 500 by default. The above code changes that interval to 0 to prevent it from running again and again. As Stewart correctly pointed out, this can be very annoying for the user as every time the form opens, they get this error message. In my case, I want the user to be annoyed enough to correct this immediately as several things break if this path variable points to an invalid path.

                Comment

                • zmbd
                  Recognized Expert Moderator Expert
                  • Mar 2012
                  • 5501

                  #9
                  I can understand that...

                  Here's a suggestion:
                  When I check for such things, I have in the on_open event of the form the file check (I use the DIR() function).
                  If the file is there then all is good and continue with the form opening or I try to locate the file based on information in the database tables.
                  If the file is missing, then I open the configuration form passing to it a message to the user that the configuration is wrong. I normally design my forms with a lable control that I can display user feed back and will parse open agruments.
                  Depending on the situation, I either open this form as a dialog-modal which pauses the calling code until the form is closed, or I simply set the on_open(cancel= true) following the configuration form so that the calling form never opens.

                  Just a thought...

                  Comment

                  • glinkoswald
                    New Member
                    • Jul 2013
                    • 8

                    #10
                    Just to clarify, the FileExists() function here is a wrapper for the DIR() function with a few bells and whistles.

                    I considered your strategy of opening the configuration form if it's bad, but in this case, the instructions are to the user to seek support. That configuration form is password protected, so they won't be able to fix this issue anyway (a sophisticated user can get around it, of course, as it's not robust, but I'm trusting that a sophisticated user will be able to understand and fix the problem). Otherwise, that's a great suggestion.

                    The reason I like Stewart's solution is that it allows the intended target form to go ahead and open the background, giving the user the security that they're headed in the right direction even if there's an error. With the On Load event, the form is not drawn before the error MsgBox is displayed, and that may give the user the sense of "Oh crud, am I even in the right place?"

                    Thanks to both of you for the suggestions.

                    Comment

                    • zmbd
                      Recognized Expert Moderator Expert
                      • Mar 2012
                      • 5501

                      #11
                      "Oh crud, am I even in the right place?"
                      User feed back and yummy lolipops are always the right way to go :)
                      However, you can provide the information in the message box in the onload event...
                      Code:
                      MsgBox "Step 2 of 10" & vbCrLf _ 
                         & "Unable to open the form" & vbCrLf _ 
                         & me.Name & vbCrLf _
                         & "for data input or update because " _
                         & "one of the required files is missing." _ 
                         & vbCrLf & vbCrLf _
                         & "Please Contact IT Support or the DBA", _
                         vbCritical+vbOKOnly,"Contact IT Support"
                      Then still cancel the open event and then bounce them back to a safe form... main menu, etc...

                      Comment

                      • glinkoswald
                        New Member
                        • Jul 2013
                        • 8

                        #12
                        Aha, that's a great idea.

                        In this case, this is a primary form, and some functions are still available to the users even if the path is not set. So I want them to be able to open and use the form even after they've been warned of a potential future problem. There is further error checking later on the next form that actually requires the path to be set that stops them at that point, bouncing the back to a safe form.

                        Comment

                        • Nauticalgent
                          New Member
                          • Oct 2015
                          • 103

                          #13
                          Late to the party (as usual), but if I ever meet Stewart Ross I will buy him a beer.

                          This is brilliant. Absotively, posilutley brilliant.

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32655

                            #14
                            He's a little less active now than he was before, but he's certainly a very valuable expert and moderator. At one time he even took charge of managing the Access forum as a Team Leader. As you can see he's no mean intellect.

                            Comment

                            • Nauticalgent
                              New Member
                              • Oct 2015
                              • 103

                              #15
                              I have researched many times about the order of events; there are times when the Before and After Update events just do not behave like I would want them to. I was able to use this "hack" and combine it with a Me.TimerInterva l = 500 on the form's OnCurrent event and achieve EXACTLY what I was trying to do.

                              I simply cant believe MS does not provide a specific event of this, obviously there is a need for it.

                              Comment

                              Working...