Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Test if Field on Form is Changed

Posted on 2002-05-14
5
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
carpediem earned 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

636 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