|
-
Jan 25th, 2006, 06:52 AM
#1
Thread Starter
Member
Closing a User Form
I have a User Form which includes a button 'Close Form'. This clears all the data entered on the form and on a worksheet.
If the user closes the form using the 'X' button at the top right of form, the code doesn't work.
How can I get the code to work when the 'X' button is used?
Thanks
-
Jan 25th, 2006, 06:54 AM
#2
Hyperactive Member
Re: Closing a User Form
Try the Form (Closing) event ...
VB Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
MsgBox("Closed")
End Sub
My software never has bugs. It just develops random features.
I RATE, YOU RATE!!!
-
Jan 25th, 2006, 06:56 AM
#3
Hyperactive Member
Re: Closing a User Form
oh .. I am sorry ... you are not talking about VB.NET...
My software never has bugs. It just develops random features.
I RATE, YOU RATE!!!
-
Jan 25th, 2006, 08:35 AM
#4
Lively Member
Re: Closing a User Form
Take a look at UserForm_Terminate()
-
Jan 25th, 2006, 09:31 AM
#5
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jan 25th, 2006, 10:46 AM
#6
Lively Member
Re: Closing a User Form
Dkenny's solution is the way to go.
-
Jan 25th, 2006, 10:53 AM
#7
Re: Closing a User Form
Thats a good solution but the user might get confused if the clicking of the 'x' doesnt do anything so its good that you place the call to click the button. 
Here is my CodeBank entry on how to disable the 'x' so its greyed out in case your interested.
http://www.vbforums.com/showthread.php?t=363931
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 25th, 2006, 11:01 AM
#8
Re: Closing a User Form
Rob
In my method, I assume that the the cmdCancel_Click event runs whatever code is needed and then hides or closes the form - therby giving the user the impression that clicking the 'x' does close the form.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jan 25th, 2006, 11:09 AM
#9
Re: Closing a User Form
Yes, I mentioned you had the call to the click event of the button.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|