Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Record with Button - Again

Status
Not open for further replies.

vfisher

Programmer
Apr 15, 2002
40
US
I'm trying to stop Access from saving a record unless the "Save" button is clicked. I put the following in the "BeforeUpdate"Event. DoCmd.CancelEvent

I have the following code on the "Save" Button:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

When the "Save" button is clicked, I get the following error message:

"You canceled the Previous Operation" and it won't save the record.

Can anyone Please tell me why???

Thanks.
 
Your problem lies in timing.....

From Access 2000 Developer's Handbook

When you save the current record by either pressing the Shift+Enter or selecting Records -> Save Record (which is the form of save you are using), the following events occur:

Control BeforeUpdate -> Control AfterUpdate -> Form BeforeUpdate -> Form AfterUpdate


So with your before update, you are canceling the Control BeforeUpdate, and therfore the Save command is never being run.

Hope this helps clear it up There is no I in team. [elf]

Robert L. Johnson III, A+, Network+, MCP
robert.l.johnson.iii@citi.com
 
I know I'm being dense. If i set the cancel = false before my I execute the save behind my button, with that correct this problem. If so, what is the syntax for this. Or is this the way it should be done?

Thanks
 
Hi!

What you want to do is declare a form level variable in the General Declarations portion of the form called bolSave(it is a boolean type). In the form's Load event set bolSave = False. In the button click set bolSave = True then save the record. Use this code in the BeforeUpdate event

If bolSave = False Then
Cancel = -1
Else
bolSave = False
End If

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top