Using a shared function in an expression of a form

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

Claude du Québec

Guest
Hi everyone,
I have a button named BtnSaveAll on my form named FrmCategories, I want to check if any changes has been made to any fields on that form, by surfing the net, I found some code that seems to do exactly what I want, even if a user but one letter in a textbox and delete that letter the code will see that no changes were made, but I can't seem to find out what is the expression I have to enter in this code below: (You'll find the code I wish to use below this one).I receive an error BC30469 when entering the code on my form closing:

Private Sub UpdateCategories()
'ADD SQL PARAMS & RUN THE COMMAND
Try
SQL.AddParam("@CategoryID", CategoryIDTB.Text)
SQL.AddParam("@Category", CategoryTB.Text)
SQL.AddParam("@ImageDirectory", ImageDirectoryTB.Text)
SQL.AddParam("@ProductFrom", ProductFromTB.Text)
SQL.AddParam("@ProductTo", ProductToTB.Text)
SQL.AddParam("@ImageFrom", ImageFromTB.Text)
SQL.AddParam("@ImageTo", ImageToTB.Text)
SQL.ExecQuery("UPDATE Categories " &
"SET Category=@Category,ImageDirectory=@ImageDirectory,ProductFrom=@ProductFrom,ProductTo=@ProductTo,ImageFrom=@ImageFrom,ImageTo=@ImageTo WHERE CategoryID=@CategoryID;")
If SQL.HasException(True) Then Exit Sub

MessageBox.Show("YOUR CHANGES HAS BEEN SAVED.", "Data saved")
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
Private Sub BtnSaveAll_Click(sender As Object, e As EventArgs) Handles BtnSaveAll.Click
UpdateCategories
End Sub

Private Sub FrmCategories_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If FormsTextBoxesAltered.TextAltered = True Then
MessageBox.Show("You need to click on the SAVE DATA button before closing this form.", "SAVING REQUIRED!")
End If
End Sub

Here is my class to check if any textboxes has been changed from the original:

Public Class FormsTextBoxesAltered
Inherits System.Windows.Forms.TextBox
Private Property OriginalText As String
Public ReadOnly Property TextAltered As Boolean
Get
If OriginalText.Equals(MyBase.Text) Then
Return False
Else
Return True
End If
End Get
End Property
Public Overrides Property Text As String
Get
Return MyBase.Text
End Get
Set(value As String)
Me.OriginalText = value
MyBase.Text = value
End Set
End Property
End Class

1592272.jpg1592273.jpg


Thank you for your time


Claude from Quebec, Canada

Continue reading...
 

Similar threads

C
Replies
0
Views
183
Claude du Québec
C
C
Replies
0
Views
111
Claude du Québec
C
C
Replies
0
Views
207
Claude du Québec
C
Back
Top