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
[code=vb]
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.SetF ocus
Exit Sub
End If
SetConnection 'My database connection
CheckConnection rs 'Checks whether the recordset is open/close
Screen.MousePoi nter = 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.MousePoi nter = vbDefault
-------------------------------------------------------------------------------
Private Sub Form_Unload(Can cel As Integer)
If MsgBox("Do you want to save?", 32 + 4) = 6 Then
Cancel = 1
End If
End Sub
[/code]
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
[code=vb]
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.SetF ocus
Exit Sub
End If
SetConnection 'My database connection
CheckConnection rs 'Checks whether the recordset is open/close
Screen.MousePoi nter = 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.MousePoi nter = vbDefault
-------------------------------------------------------------------------------
Private Sub Form_Unload(Can cel As Integer)
If MsgBox("Do you want to save?", 32 + 4) = 6 Then
Cancel = 1
End If
End Sub
[/code]
Comment