[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

Dirty record auto save

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
cwbarrett
Asked:
cwbarrett
  • 4
  • 4
4 Solutions
 
Rey Obrero (Capricorn1)Commented:
use

if me.dirty then me.dirty=false

'your command to open the 2nd form goes here
0
 
cwbarrettAuthor Commented:
But will that save the record?  I don't see a save command there if it's dirty.
0
 
Rey Obrero (Capricorn1)Commented:
me.dirty=false  ' will save the record
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
cwbarrettAuthor Commented:
Place in which of form #1 event? Onlostfocus?  On deactivate?
0
 
Rey Obrero (Capricorn1)Commented:
how do you open the 2nd form?
0
 
cwbarrettAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
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
 
PatHartmanCommented:
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
 
cwbarrettAuthor Commented:
Worked, thank you, and thank you for the bug info.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now