Hello World
This is a follow-up question from http://www.thescripts.com/forum/thread742864.html for the reason that Killer42 and Mohan wants me to start a new thread... so this is it.
The question... can you handle (form) unload event without prompting a message box but to be able to prompt a message box to the user if he wants to save before closing ... instead of just closing the window -Kabyr.
Here's the sample code:
Where Text1.Text is generated -
Private Sub cmdSave_Click()
-
If Text2.Text = "" Then
-
MsgBox "Please type in course title.", 48
-
Text2.SetFocus
-
Exit Sub
-
ElseIf Text3.Text = "" Then
-
MsgBox "Please type in the description of the course.", 48
-
Text3.Text.SetFocus
-
Exit Sub
-
End If
-
-
SetConnection 'My database connection
-
CheckConnection rs 'Checks whether the recordset is open/close
-
Screen.MousePointer = vbHourglass
-
-
If AddCourse = True Then
-
'Add new course
-
rs.Open "Insert Into Courses ([CourseID],[Title],[Description]) Values " _
-
& "('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "')", con, 3, 3
-
MsgBox "New course has been successfully added.", 64
-
Unload Me
-
Else
-
'Update course
-
rs.Open "Update Courses Set [Title]='" & Text2.Text & "', [Description]='" & _
-
Text3.Text & "' Where CourseID='" & Text1.Text & "'", con, 3, 3
-
MsgBox "Course has been successfully updated.", 64
-
Unload Me
-
End If
-
Screen.MousePointer = vbDefault
-
-------------------------------------------------------------------------------
-
Private Sub Form_Unload(Cancel As Integer)
-
If MsgBox("Do you want to save?", 32 + 4) = 6 Then
-
Cancel = 1
-
End If
-
End Sub
-
-
5 2280
This is what really the problem in that thread... http://www.thescripts.com/forum/thread742864.html
But it depends on the form and/or type of application. Let us say for an instance we have 1 form and containing all the list of any record, then when adding/modifying a particular record we're using another form and it is shown as vbmodal. What if the user add new record, how can you unload that form without prompting a message box? : )
So how to rectify this when MODAL forms are shown.
Use this logic when you are using edit command button in your form, other wise it will popup even any keypress in your form controls.
[Thinking] Setting the form to invisible rather than unloading, I think this is not a better solution.
VACEPROGRAMER, I've split your stuff to a new thread, as it is completely unrelated to the original question.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Harry J. Smith |
last post by:
I have written a Visual Basic program that does a long calculation and
writes the results to disk as it runs. If I click the Close button the
window closes but the program keeps running. How can I...
|
by: sidd |
last post by:
Hi all,
how do i exit out(unload) of a windows service in case of an error.
so i have a code block as follows
try
{
}
catch(exception ex)
{
//log to event log
|
by: David A. Beck |
last post by:
I have a frameset with an index frame and a main frame. The aspx pages in
the main frame are loaded based on the hyperlinks clicked in the index
frame. In any aspx page in the main frame I want to...
|
by: hal |
last post by:
I have an application that includes an activex component
that consumes resources that must be released when the a
page is unloaded.
Toward this end I subscribe to the unload event of the
body...
|
by: Hal |
last post by:
My most sincere gratitude to anyone who can help me work
around this!
I have work that needs to be done in javascript on the
client whenever a page is unloaded.
To this end, I subscribe to...
|
by: bburkhart |
last post by:
I am running into a issue catching a thrown error in the Control.Unload event. Is it possible to throw an Application error from the Unload event and have the global.asax Application_Error catch it?...
|
by: Mike |
last post by:
I have a web form in my application that will be used for both viewing and
updating information. I have a requirement that if any data has been changed
on the page and the user attempts to leave...
|
by: Gauthier Segay |
last post by:
Hello,
I've an application where all my pages implement a PAGE_CODE string
property, this property is stored in HttpContext.Current.Items.
In some page, I must persist data in session while...
|
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= |
last post by:
It seems that one page XBAP whose Unloaded event
never get called, I need put some clearing stuff (I.G stop dispatcher time)
when
user close browser, it unload event doesn't work, where
shall I...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |