Solved

Lost Focus, Dirty

Posted on 2013-12-12
2
351 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 35

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

776 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