Solved

Lost Focus, Dirty

Posted on 2013-12-12
2
340 Views
Last Modified: 2013-12-29
Experts,
Is the below advisable in a multi user environment?

Private Sub Form_LostFocus()

    DoCmd.RunCommand acCmdSaveRecord
    'sometimes get error of same person trying to edit record and not sure if save record is cause of it.
   
End Sub
0
Comment
Question by:pdvsa
2 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 300 total points
ID: 39714241
The form's GotFocus and LostFocus events run ONLY if the form has no control that gets the focus so your code is never executing.

Access is very conscientious when it comes to saving data.  You don't need to do anything in a bound form to make a save happens.  Access takes care of it whenever the record pointer changes and there are numerous situations where this would happen including closing the form.  Most people struggle with stopping Access from saving their data - mostly because they don't understand that the Form's BeforeUpdate is the key and tend to use the shotgun approach to coding.

In general, I would not recommend putting any validation code or code that forces a save in the LostFocus event of a control.  Just because the user tabbed into the control doesn't mean he changed anything so you don't need to take any action regarding validating or saving since nothing was changed.  The BeforeUpdate event of the control/form are where most validation would be placed.

The Dirty event is also inappropriate for validation/force saving because it fires as soon as a single character is typed so that is way too soon in most cases to do any validation and you certainly don't want to save a record that contains only a single character.
0
 

Author Closing Comment

by:pdvsa
ID: 39745474
thank you
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now