About events and when and what code to write into them:
First of all events are happening and in their event method you react to them. A button for example, does nothing, when you click on it and have no code in click. But while that's the most frequently used and first used method most developers ever code, it's not typical for events to have no default behaviour even without code in them.
The events all can be edited and you can program code into them. If events always would need to be kept empty, you wouldn't get the opportunity to code in them. Some events, like KeyPress, even give you parameters, eg which key(s) were pressed. Also the valid event can contain code, but what is the event named? Valid, it decides, whether the data in the control.value is a valid value. In some cases you won't accept empty values, in other cases you won't accept dates in the past, only dates in the future. You return .F., when you don't want to accpet the control value. If you don't program anything into valid, you accept any value, as empty methods automatically return .T.
When the valid event was passed and returns .T., the control also saves its value into it's controlsource. From that persepctive you don't need any save code at all, you only need to set controls controlsource value and the controls save their values automatically. The need of save code arises, if you buffer the fields you bind via controlsource, eg you set the buffering of cursors or views or tables involved. Such save code would do a TABLEUPDATE(), for example. It might do more, it might auto fill other fields or do whatever other data maniupulations, eg set a lastupdate field of a table to datetime().
The point is, that such save code cannot commit a table.field value, when the control valid has not run, in the sense of has not happened. If you call valid you still don't make the control save its value to the controlsource, you only do your own code in it, but don't trigger the valid event. You only trigger it by moving focus to another or (as weird as it may sound) the same control). Then the valid happens.
If you program [tt]REPLACE somefield WITH this.value IN sometable[/tt] within the valid event of the control, you do, what VFP automatically does, when you set the controlsource preoprty to [tt]sometable.somefield[/tt]. VFP does a lot of things for you without any code, if you simply use it correctly and know the properties and their meanings.
So in short again:
You set a textbox.controlsource to sometable.somefield and thereby bind the textbox to that field twoways - it displays the fields value and edits in the textbox go to the field.
You only need to set focus anywhere else to save the displayvalue. A savebutton on the form does this, even without any click code in it. Also closing the form without clicking it will make the focus be lost and the field be set to the new value.
So in this simple setup you don't need anything else, no code in clicks or valid to let the textbox work. It's just a very simple setupand you might want more control. eg validate your data.
So in short about the valid event:
You write code into it checking the validity of data and allowing its saving to the table field by RETURN .T., disallowing with RETURN .F., you can also return 0 to stay in the control, you can also return a value N being the offset in tab order you want to set focus to other controls and finally you also can return ThisFORm.someothercontrol to set focus to someothercontrol, if that matters to set the value correctly. But you don't save data in the valid, the saving of buffered data should be a separaate method, as you had, but it should only run, after the valid has happened.
Bye, Olaf.