Solved

Test if Field on Form is Changed

Posted on 2002-05-14
5
170 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now