If a controls changes in a form, show a message to force saving the data

  • Thread starter Thread starter Claude du Québec
  • Start date Start date
C

Claude du Québec

Guest
Hi,

I have a form named "frmCategories" on which I have textboxes that a user can change. If that happens and the user don't click on the button save (BtnSave) then I want a message (ShowFrmMsgTBChangeSoSave) to be displayed, I wrote some code but even if a change is made, no form appears.

Below is the code followed by the form image:

Thanks in advance for the help

Claude From Quebec, Canada

Private Sub BoxHasChanged()
'Iterate through all controls and handle them according to their type
For Each c As Control In Me.Controls
If TypeOf (c) Is CheckBox Then
AddHandler CType(c, CheckBox).CheckedChanged, AddressOf SomethingChanged
ElseIf TypeOf (c) Is RadioButton Then
AddHandler CType(c, RadioButton).CheckedChanged, AddressOf SomethingChanged
ElseIf TypeOf (c) Is TextBox Then
AddHandler CType(c, TextBox).TextChanged, AddressOf SomethingChanged
End If
Next
End Sub

Private Sub SomethingChanged()
ShowFrmMsgTBChangeSoSave()
End Sub

Private Sub FrmCategories_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
BoxHasChanged()
End Sub
Private Sub ShowFrmMsgTBChangeSoSave()
Try
Dim SmallerMsg As New FrmMsgSmaller
FrmMsgSmaller.Close()
FrmMsgSmaller.TextBox1.Text = ""
FrmMsgSmaller.TextBox1.Text = "There was changes made, please click the save button!"
FrmMsgSmaller.Show()
Dim SW2 As New Stopwatch
SW2.Start()
Do
Application.DoEvents()
Loop Until SW2.ElapsedMilliseconds >= 2000
FrmMsgSmaller.Hide()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub



1609648.jpg

Continue reading...
 
Back
Top