Solved

Test if Field on Form is Changed

Posted on 2002-05-14
5
174 Views
Last Modified: 2012-05-05
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
Comment
Question by:jtrapat1
5 Comments
 
LVL 1

Accepted Solution

by:
carpediem earned 100 total points
ID: 7009635
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 7009636
How about the textbox Change event procedure:

Private sub Text1_Change()
  ' text has changed
end sub
0
 
LVL 13

Expert Comment

by:John Mc Hale
ID: 7009804
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7009928
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
 
LVL 4

Expert Comment

by:RichW
ID: 7011243
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question