Full Version: Save current change before launch new form.
UtterAccess Forums > Microsoft® Access > Access Forms
binetp
Form X is open. Changes are made. A cmd button launches frmqryUnit. Want current changes to save prior to opening the form. i know this is Access 101...but please just tell me where to place the acSaveRecord!!!
Private Sub cmdUnitList_Click()
On Error GoTo Err_cmdUnitList_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmQryUnit"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Exit_cmdUnitList_Click:
Exit Sub
Err_cmdUnitList_Click:
MsgBox Err.Description
Resume Exit_cmdUnitList_Click

End Sub
Freaker
I would not use acSaveRecord. If the form is attached to the recordset all you need to do is place the following code wherever you want to save the record (I would do it just before I issue the OpenForm command).
!--c1-->
CODE
If Me.Dirty = True then
' Save Record
me.Dirty=False
End If

I hope this helps
binetp
Works like a charm! Thanks
Steve Schapel
Freaker,
o problem with adjusting the Dirty property as you have done. But curious as to why you don't like the other option. I think Paul was referring to this:
DoCmd.RunCommand acCmdSaveRecord
... which is perfectly fine as far as I know.
Steve Schapel
Paul,
So, this is not "Access 101".
Access 101 says that you do not need to explicitly save the record. Neither using acCmdSaveRecord nor Me.Dirty. Not necessary because the record will automatically be saved when the focus moves from Form X.
So the reason why some people do explicitly save in these circumstances is to allow for a "bug" in Access. This bug relates to examples where the data that has been entered in the form is invalid, for example because it violates a user-defined Validation Rule, or there is no data entered in a Required field. In some circumstances, the form will close and silently discard the invalid new record with no warning. Maybe sucha consideration does not apply in the case of your form, in which case you can use Access 101 approach. sad.gif
Freaker
Steve,
Sorry if my post was misleading, I was not trying to say that there is an issue with acSaveRecord. It's just that I don't do it that way, that's all. I also like to check that something needs doing before doing it. If I wanted to see if the form needed saving I would use If Me.Dirty = True Then ... So for me I find it easier to read if the next line is Me.Dirty = True.
raig
Steve Schapel
Ok, Craig, that's cool. Got lost in the translation. sad.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.