Results 1 to 4 of 4

Thread: Close or Unload

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Close or Unload

    Which event is the best place to put code that should be run when the user closes a form? I have code in the Unload event of a form that is supposed to send an email and delete all data from a table. It's always worked for two users, but not for a new user. I'm not sure what she did differently. The way they close the form is to click the x button in the control box.
    Is there a reason the code should be in the close event rather than the unload event? I've typically used the close event just to check if the user really wants to close the form.
    Thanks.
    Tengo mas preguntas que contestas

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Close or Unload

    The Form_Unload event would be the better event to trap for canceling of
    the form from unloading if a user wants to change their mind.

    The Close event occurs after the Unload event, which is triggered after the form is closed but before it is
    removed from the screen. When you close a form, the following events occur in this order:

    Unload → Deactivate → Close

    When the Close event occurs, you can open another window or request the user's name to make a log entry
    indicating who used the form or report.

    The Unload event can be canceled, but the Close event can't.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Close or Unload

    Ok, thanks, I guess I got the verifying the close mixed up. Haven't actually checked for that in a long time.
    But in the code below, ClearTempLog is a sub that deletes all data from the TempLog table, and it didn't run. That's what I can't figure out.
    VB Code:
    1. If MsgBox("Are you finished editing the " & mstrDbName & " comments?", vbYesNo + vbQuestion, "Editing Complete?") = vbYes Then
    2.             DoCmd.SendObject acSendTable, mstrLogName, acFormatTXT, "Boss", , , mstrDbName & _
    3.             " Editor Changes", mstrDbName & " changes attached.", True
    4.             ClearTempLog
    5.         End If
    Tengo mas preguntas que contestas

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Close or Unload

    Place a breakpoint at the If MsgBox line. Then run your form and close it answering it with yes. Step
    through and see where the code execution is going. Is it evaluating the vbYes? Is it going into the
    ClearTempLog procedure but generating an error so it jumps out of that procd?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width