Results 1 to 9 of 9
  1. #1
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615

    Order of events on forms?

    This one has me baffled.

    From one of my forms, I use this code to open another one in dialog mode:

    Docname = "translate form"
    gbSQL_Failed = False
    gbVerb_Only = False
    gbUse_Keywords = False


    gsCurrent_English = English
    PushForm
    DoCmd.OpenForm Docname, , , , , acDialog

    Pushform is a procedure to hide the current form but not close it.

    The problem is in the Translate Form.

    According to Microsoft, the order of events when opening the form should be:

    Open -> Load -> Resize -> Activate -> Current

    But by using debug.print, I have found the order of events to be this when I open the form:

    Current -> Load -> Current -> Open (Activate did not fire at all)

    Does anyone know what's going on here? The order is backwards and On Current fires twice!

    It's a pain because On Current depends on values set by On Load, but which are messed up by On Open.

    Thanks for any insight.

    John

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are you sure they're firing backwards, and not just displaying in the Immediate window in reverse order? I just tested with message boxes and the order was as advertised by MS (and the current event only fired once).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I had the same thought - I put timings on the debug statements, and yes, they are in the order I indicated. Strange.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post a sample db here that exhibits that behavior?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I have to do some digging here. If I export the form to another unrelated database, and edit the code until it compiles (procedure calls, global variables etc.), then the event order is exactly as it should be. Maybe my code has some strange side-effects.

    John

  6. #6
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In my On Load event I had this:

    Me.RecordSource = gsTranslate_SQL

    By using debug.print, I found that this statement caused the On Current event to fire, so I moved it to On Open.

    So, here is what is happening: (!)

    On Open runs first as expected.
    In the On Open, it executes this statement: Me.RecordSource = gsTranslate_SQL, which causes the On Current event to fire.

    When On Current has completed, control passes back to the On Open, which then finishes.

    When the On Open has finished, the On Current does not run again.

    The problem is, the On Current event depends on various things that On Open does, in order to work properly.

    How do I get around that one? Is there any way of stopping the On Current from running, when I have no control over it?

  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
    Quote Originally Posted by John_G View Post
    Is there any way of stopping the On Current from running, when I have no control over it?
    I'm not entirely clear on what you're doing, but perhaps I can think of a way around that issue. You could use a form level variable, called lets say booRunCurrent. Set it to false until you want it to run, then set it to true. In your current event, test that variable and only run your code if it's true. That doesn't stop the event from firing, but will only run the code within under your controlled circumstances.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    That was the solution. Interestingly, the On Load event also ran inside the On Open event, probably because it wanted to run the On Current.

    I had to explicity call the On Current procedure (Form_Current) as the very last line in the On Open procedure.

    Thanks for the suggestions.

    John


    Worth knowing these subtle "features".

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. I've set the recordsource in the open event before, but I guess I didn't have the interdependency between events that you have.
    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: 9
    Last Post: 11-22-2011, 05:23 PM
  2. Different Events
    By jo15765 in forum Programming
    Replies: 2
    Last Post: 12-07-2010, 12:45 PM
  3. Forms Order By not working
    By cowboy in forum Forms
    Replies: 3
    Last Post: 04-21-2010, 10:29 AM
  4. Order of data in forms
    By Penz in forum Forms
    Replies: 7
    Last Post: 11-03-2009, 05:27 PM
  5. Events Report, please help!
    By Suzan in forum Reports
    Replies: 3
    Last Post: 04-19-2006, 01:11 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