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 "Data = " & Adodc1.Recordset.Fields(txtFields(index).DataField).Value
Debug.Print "Text = " & 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.
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 "Data = " & Adodc1.Recordset.Fields(txtFields(index).DataField).Value
Debug.Print "Text = " & 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.