Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataChanged not working like I expected...

Status
Not open for further replies.

MikeCox

Programmer
Jun 4, 2001
340
US
Hi.

My main form has 50 or so textboxes (txtFields()), each bound to an Adodc. One of the fields is LastUpdatedBy which is to show the NT user name of the last person to make a change to any of the information. Naturally, I thought that txtFields(index).DataChanged = True if the user made a change to the info in the textbox, but hasn't commited the change to the database yet. For some reason, DataChanged is always returning False (I'm checking it in the txtFields_LostFocus routine), even though the .Text does not match the Field.Value in the cooresponding field.

Here's my code:

Private Sub txtFields_LostFocus(index As Integer)

If Adodc1.Recordset.Fields(txtFields(index).DataField).Value <> txtFields(index).Text Then
txtFields(38).Text = Now
txtFields(46).Text = UserName
Adodc1.Recordset.Update
End If

Debug.Print &quot;Data = &quot; & Adodc1.Recordset.Fields(txtFields(index).DataField).Value
Debug.Print &quot;Text = &quot; & txtFields(index).Text

End Sub

The condition in the If statement is never true, and the debug statements print exactly the same values, even though the underlying database field is never actually updated with the new text value from the textbox. I resorted to this approach since DataChanged wasn't suiting my needs. Why doesn't this code compare the Field value with the text value? It almost seems like VB is getting it's Field value directly from the txtFields(index).Text, instead of the database, which definately doesn't seem right.

Thanks for any ideas you may have.

-Mike
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Answered my own question, I just moved the code to the txtFields(index)_Validate routine and it works beautifully.

-Mike Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top