• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Test if Field on Form is Changed

I'm using VB6 against an sql server database.

Is there any way or event I can check for if a textfield has been changed by a user?

I tried the DataChanged event but it doesn't seem to be working.

Thanks in Advance,
John
0
jtrapat1
Asked:
jtrapat1
1 Solution
 
carpediemCommented:
DataChanged only works if it is a bound field.  Meaning you use a datacontrol and bind that text-box to a field of that data.

The only other way I've done this in the past is good old fashioned manual comparison.  If you have to individually check each field for change this can be a pain, but if you just need to know if any data on the form has changed (for saving ect) it is quite easy.  Something like this.

Private lstrOldData as string

Private Sub Form_Load
'All of your code to load the form
  lstrOldData = FormData

End Sub

Private Sub Form_Unload
  If lstrOldData <> FormData Then
    MsgBox "Some data has changed"
  End If
End Sub

Private Function FormData() As String
  FormData = txtField1.Text & txtField2.Text & txtField3.Text

End Function
0
 
rspahitzCommented:
How about the textbox Change event procedure:

Private sub Text1_Change()
  ' text has changed
end sub
0
 
John Mc HaleCommented:
Try TextField_AfterUpdate() method.

Private Sub TextField_AfterUpdate()
If me.TextField.Text <> me.TextField.OldValue Then
' Value of field has changed, and do something
End If
0
 
Anthony PerkinsCommented:
carpediem,

>>DataChanged only works if it is a bound field.  <<

I beg to differ.  Do the following and you will see what I mean:
1. Create a new project.
2. Add a Text Box (Text1)
3. Add a Command Button (Command1)
4. Add the following code:

Private Sub Command1_Click()

Debug.Print Text1.DataChanged

End Sub

Once the DataChanged Property is set to true, you are resposible for resetting it.

Anthony
Anthony
0
 
RichWCommented:
Working from Anythony's comment you could do the following to check all textboxes on a form:

Private Sub DataChanged()
Dim txt As Object
For Each txt In Me
    If TypeOf txt Is TextBox Then
        If txt.DataChanged Then
            MsgBox txt.Name & "'s data has been changed"
        End If
    End If
Next txt
End Sub

RichW
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now