Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

glgcag1991

Programmer
Oct 15, 2007
72
0
0
US
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!
 
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.

*Sigh*

D

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
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!
 
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
 
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 [highlight #FCE94F]pop up[/highlight] and [highlight #FCE94F]modal[/highlight] to yes and then the only the form has focus.

[flush]

Michael

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top