To explicitly save, replace the DoMenuItem (your #9) with:
Me.Dirty = False
A better solution is to move all the record validation code (your step 6)
into Form_BeforeUpdate. Just doing that avoids all the other steps. There is
no longer any need to mess with form level variables (SaveRec) or try to
force the user into a particular sequence.
I have not worked through all your steps (since they are probably
unnecessary), but I didn't see anywhere where SaveRec was set back to False
after a save, so if it were possible for the user to move record after an
edit, it would not be re-initialized.
You may also need to be aware that Access can silently lose your entry if
you use the Close action in a macro, or the Close method in code (as
distinct from the close button on the right end of the form's Title bar.)
More info:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<Andy_Khosravi@bcbsmn.comwrote in message
news:1166209342.546390.195090@73g2000cwn.googlegro ups.com...
Quote:
I'm having a problem with an entry form on one of my applications. It
would appear that the save action is sometimes not working, and is
generating no error when it fails. I'm hoping one of you may have some
insight into what is causing the problem.
>
I'll describe only the general outline since the actual code is several
pages long.
>
1. Entry form opened in Data Entry mode
2. Global variable SaveRec set to False on form load.
3. User displayed 2 bound controls (ID [AutoNumber], and Title [Text])
and an unbound control (Description [memo])
4. User fills in controls and AutoNumber field is generated
5. User clicks Save button
6. Validation run to insure all fields filled in and that AutoNumber
field contains a value
7. Value in AutoNumber field saved to GlobalVariable IDHold
8. Global variable SaveRec set to True
9. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
10. Open recordset on table where the above record was created using
criteria stored in IDHold
11. If recordcount = 0, display error and exit Save Button module Else
continue
12. *Many other steps beyond this, but they appear to work just fine.
>
*The Form's Before Update event occurs immediatly after the save record
command.
Form Before Update
If SaveRec = False
Me.undo
End if
End sub
>
My problem is on step 11. 95% of the time the record is saved
correctly. However, sometimes the record isn't found because it wasn't
saved. No error is being generated so I have no idea why the save did
not go through. Some users have this problem occur more than others and
the ones that have it happen most often are users located offsite
(WAN). If this problem does occur, the user has to click the Finish
button once or twice more before the record is finally out there and
available for the recordset to find.
>
My question is this: does the save record command wait to complete
before advancing to the next line of code, or will it only initiate the
save action before moving on? By what I can tell, it would appear to be
the latter. If it only initiates the save, is there anyway to delay the
code until the save action is complete?
>
Thanks in advance for any advice you might have!
>
P.S. I could just do the whole thing with a recordset and use the
.update method, but the users want to be given the record number while
they are entering it rather than after.