Well without seeing your code to know how you do your logoff procedure, ideally you would put an SQL statement in a function which would write the statement to database. Then you would call this function from a log off button or something like the Form_Terminate() event.
So I would start your search there at the form_terminate() event for your form and call a function which will insert the SQL into the database. This event fires whenever the form is closed (like pressing the X in the corner).
Now I say call a function to do this instead of writing the SQL in the event for an important reason. You want to be able to call this function from different locations. You want to call it from the menu when they select "exit" (if your application has a menu), you will want to call it from a log off button (if you have one), and you want to call it from the terminate event. It is better to have this code to record the time in one location so that in the future you can reuse this function or if you need to make changes to how this information is recorded to the database you change it only in one spot and it will change it for all three locations (menu, button, and the terminate event) simultaneously.
I hope that makes some sense to you and gives you an idea of how to go about doing this.
Enjoy!
"At DIC we be terminating code writing code ninjas... we also terminate others on a contract basis."