Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Code at close of form isn't working when user closes database

Code at close of form isn't working when user closes database

Code at close of form isn't working when user closes database

I have an unbound form that on open I store the field values in the .tag of the field. On close of the form I run a module to compare and then record any edits. I am having issues with users closing the database with the form open and the edit checking isn't firing, hence the edits aren't recorded. (At least that is what seems to be happening.)

Any best practices for unbound forms you might suggest? Running the code on a timer may miss edits if the user closes the db in-between code execution. The only thing I can think is to run my edit check after exit of the unbound fields.

I appreciate the help!

RE: Code at close of form isn't working when user closes database

1DMF: Would <AfterUpdate> fire on an unbound form?

This post, just might solve a problem that I've had for years, whereby a client-server app should log when users close the app - in many cases it doesn't.
I always understood that the application.close event propagated down and fired all open form.close events - the question is: does it?

If not, it's almost like we (ourselves) must call a module that checks all open forms and fires their code off.



Never argue with an idiot, he'll bring you down to his level - then beat you with experience.

RE: Code at close of form isn't working when user closes database

Here is what I have done:

- per 1DMF I have check for edit that runs on form update
- on form unload I check for edit too so that if the user hasn't tabbed out of the field they are editing prior to completely closing the database, I get another chance to commit the edit

So far it is working but I'm definitely going to bind the form when I get a chance cuz it is just too much code and mess to keep it unbound

Thanks for the help!

RE: Code at close of form isn't working when user closes database

Sorry for late reply, the answer is yes, update fires on unbound.

The update event is not a DB update, but a form control, so even if they are unbound when they are changed(updated) the form update event fires.

Bound/unbound is simply whether the data in a form control is directly linked to the backend table column.

If you build yourself classes for performing tasks (models), you can then user the MVC paradigm to update backend DB from unbound form controls.

It takes time to do and bound controls can seem like the quick fix at times (and sometimes is still the correct approach), but MVC presentation layer / business logic separation is always a good idea!

It means your classes become re-usable else where and helps with keeping your code DRY, eliminate bugs, and increase development.

Keep writing the same business logic on multiple forms is tedius, time consuming, bad practice, and can become code spaghetti and a maintenance nightmare.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: Code at close of form isn't working when user closes database

I've had similar issues in the past and to get around the user closing the database instead of the form, I set the attributes pop up and modal to yes and then the only the form has focus.



It is said that God will give you no more than you can handle. I just wish God didn't think I was just a bad ass.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close