PDA

Click to See Complete Forum and Search --> : Lose las edit with update


Johannes Schade
Sep 14th, 2000, 10:56 AM
Dear Friends
I write a front-end to a SQL Server database in VB6 using ADO recordsets. I have a couple of bound text boxes. I use AdoDc1.Recordset.Update on the Form_Unload event. However when I edit something in a text box and then quit immediately (without clicking anywhere else), I lose the edit in the text box. If I click into another textbox after the edit, then the edit will be saved by the update method.
I tried to use Me.Text1.SetFocus in the Form_unload event to try to mimick this additional mouseclick, but it does not do it. AdoDc1.Move 0 will save the edit, but this triggers AdoD1_MoveCompleted which I am trying to avoid because I also have a Datagrid on the form which needs to be reloaded whenever the record changes and I do not want to reload it when quitting. There are similar problems in DataGrid where last edits are lost, but this should probably be a different post.
With Many Thanks

Johannes Schade
Sep 18th, 2000, 07:43 AM
I think I have solved my problem. I found (more or less by accident) that assigning directly into the recordset updates the recordset to the latest states of bound controls as a side-effect. So, having a test box called "Text1" bound to AdoDc1, I write into the Form_Unload event:
>AdoDc1.Recordset.Fields("Field1")=Me.Text1.Text
>AdoDc1.Recordset.Update
The first line is kind of non-sensical, but it updates the recordset to the latest state of the bound controls. The Update then saves this to the permanent storage (DB).
So I do not any more lose the last edit when quitting out of the form or the application. I hope somebody is interested and might tell me whether he/she agrees with this or whether he/she has perhaps a better solution.