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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not saving a comment

Status
Not open for further replies.

nipchop

Technical User
Jan 22, 2001
28
GB
I have a section of code that prompts a user to see if they wish to save the Comments they have just made. If they say Yes then save, if they say no then dont.

The code below as far as I am aware should do this but when you say no the comments is still saved in the table. Any ideas why?

Dim Result As Integer

Result = MsgBox("Do you wish to Save?", vbYesNo, "Save?")
If Result = vbYes Then
[chkActive] = True
[datStamp].Enabled = True
[datStamp] = Now()
DoCmd.Close acForm, "frmItemComments", acSaveYes
Else
DoCmd.Close acForm, "frmItemComments", acSaveNo
End If
 
NipChop,

If your form is tied to a recordsource then your data will save no matter what parameter you put on the end of docmd.close statement. All the acSaveYes or acSaveNo will do is save( or not save) any changes made to the form structure not the data on the form. I would need some more information about what your trying to do to be any more help.

Sorry - Shane
 
If you wnat to NOT save a field, you need to look at the "IsDirty" property and the OldValue Property of the control

the below is just a "quickie", points in the direction, but will need some research, thought and modification - BY YOU.

Code:
Dim Result As Integer

Result = MsgBox("Do you wish to Save?", vbYesNo, "Save?")
If Result = vbYes Then
        [chkActive] = True
        [datStamp].Enabled = True
        [datStamp] = Now()
        DoCmd.Close acForm, "frmItemComments", acSaveYes
Else
        If (IsDirty(Me.someField)) then
            Me.SomeField = Me.SomeField.OldValue)
        End If
        DoCmd.Close acForm, "frmItemComments", acSaveNo
End If

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Hi!

Another way would be to leave the comment control unbound, and at your prompt assign the value of the unbound comment control to the controlsource;

If Result = vbYes Then

"assign your other values to fields in your recordsource"

[fldComment]=[txtComment]
DoCmd.Close acForm, "frmItemComments"
Else
DoCmd.Close acForm, "frmItemComments"
End If

Good luck, Roy-Vidar
 
The CancelUpdate method can be used to skip saving any changes. If its not used, the form saves automatically when a move method occurs or an update method occurs.
The cancelUpdate method just discards the changes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top