Solved

Test if Field on Form is Changed

Posted on 2002-05-14
5
176 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

695 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