Solved

Dirty record auto save

Posted on 2014-01-23
9
991 Views
Last Modified: 2014-01-23
Hi,
I have a form with a button that opens a 2nd form.  The 2nd form has related records based on the 1st form's current record.  When adding a record in form 1 and clicking the button which with the record is in the detail section (continuous) I get an error on the 2nd form when adding a record.  I know it's because the 1st form's record has not been saved (referential integrity is on for this relationship)  
My question is:
1.) What is the best way to save a record on the 1st form prior to opening the 2nd?  onlost focus?  Ondeactivate?  
2.) Can I use the Menu Command saverecord in a macro?  What is the best event to attached to?
3.) Info for ondirty says it only saves a record if it has been changed.  Is a new record that has not yet been saved considered a "changed" record?

I can't seem to make saverecord work.

Help is appreciated.
Chrlie
0
Comment
Question by:cwbarrett
  • 4
  • 4
9 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 375 total points
ID: 39803866
use

if me.dirty then me.dirty=false

'your command to open the 2nd form goes here
0
 

Author Comment

by:cwbarrett
ID: 39803884
But will that save the record?  I don't see a save command there if it's dirty.
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 375 total points
ID: 39803891
me.dirty=false  ' will save the record
0
 

Author Comment

by:cwbarrett
ID: 39803901
Place in which of form #1 event? Onlostfocus?  On deactivate?
0
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)

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39803912
how do you open the 2nd form?
0
 

Author Comment

by:cwbarrett
ID: 39803939
Form #1 is actually a continous subform.  Each record has a button that opens the 2nd form based the record that the button is in.
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 375 total points
ID: 39804004
place the codes

if me.dirty then me.dirty=false

in the click event of the button, place it before the command to open the 2nd form
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 125 total points
ID: 39804295
Setting Me.Dirty to False is a trick that is supposed to get around a bug in Access and I understand your confusion.  I was completely baffled the first time I saw it used.  In fact, I thought it was cancelling the save and spent hours on the wrong path while debugging an app created by someone else.  So, I suggest that if you use it, you add a comment explaining what it does.

DoCmd.RunCommand acCmdSaveRecord

is the more standard way to save the current record.  I personally have never encountered the bug in my 20 years with Access.  I'm not even sure what the bug is.

Access automatically saves the current record whenever you leave it.  However, opening a new form or report doesn't constitute leaving the current record so you need to force the save any time you open another object.  So to repeat the previous advice, add the save command of your choice immediately in front of the instruction to open the second form/report or recordset.
0
 

Author Comment

by:cwbarrett
ID: 39805259
Worked, thank you, and thank you for the bug info.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

896 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

15 Experts available now in Live!

Get 1:1 Help Now