View Full Version : Form Saving Problems


mugman17
02-23-2001, 12:10 AM
I have a form that several people use. If they begin to use the form and do not complete a transaction ( I have a save command button) it still saves thte data. I would like it that if they do not hit the save command button it does not record the data into the table. I know this is quite easy. Its just not coming to me right now.

Thanks

Fornatian
02-23-2001, 12:16 AM
I would suggest putting code behind the close button of the form which says in shorthand:

If "Do you want to save the record" = vbYes
then
'Save
else
'Me.Undo
docmd.close
end if

not tried this out yet but seems reasonable.

Ian

Anauz
02-23-2001, 07:09 AM
how do you open the form in the first place? Access has differnet methods for you application of the form. The following will open the form in add mode.


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Company_Details"

DoCmd.OpenForm stDocName, , , acAdd


you need to place this in the clicked event of a button or something

Pat Hartman
02-23-2001, 07:55 PM
Access automatically saves a record when you move to a new one or close the form. To intercept this, you need to put code in the BEFOREUpdate event of the form. This is the last event fired before a record is saved or updated. If the record is incomplete, you can prevent the update by adding the following line of code:
Cancel = True

The Close event as suggested by Fornatian is too late. The record has already been saved. You probably should display a message box giving them the option of completing the record or cancelling without saving. If they select to cancel without saving, you also need
Me.Undo
otherwise, they'll need to hit the escape key to get out of the form without saving.


[This message has been edited by Pat Hartman (edited 02-23-2001).]

Fornatian
02-23-2001, 11:21 PM
My mistake, still learning...