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

How can I prompt to confirm changes. 1

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
CN
I have a form with textboxes that relate to data from one table. I can make changes to the data in the textboxes but it seems to save automatically, say if I click Next Record, when I go back to the one I altered and did NOT save, I notice it DID save. This isn't a good idea for me because I feel the users may accidently change the data. Can I have something that prompts me that changes have been made?


Thanks.
 
Or ... can I makes all my fields non-editable until the user clicks 'Edit', then make them editable? How could I do this?
 
In the BeforeUpdate event of the form, do something like this:

If (Me.Dirty) Then
if (Msgbox("Changes have been made. Do You want to save the changes?",vbQuestion + vbYesNo) = vbNo) Then
Me.Undo
End if
End if

To make the fields not editable until the user selects a button, in the OnCurrent event of the form, set AllowEdits property to False. Then when the button is selected set it to AllowEdits property to True.

Example:
Me.AllowEdits = False
 
I was following this post as well. Thanks for the code FancyPrairie. I have one other question.
I want the user to be able to select yes, no, or cancel.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)    
    If (Me.Dirty) Then
    Select Case MsgBox("Changes have been made.  Do You want to save the changes?", vbYesNoCancel & vbYesNo)
    Case vbNo
        Me.Undo
    Case vbCancel
        'Do not update the record, don't discard the changes, stay on the same record
    End Select
End Sub

I would like for the user to be able to go back to the record that they were just working on with all of the changes that they have made, but also not save the data.

Do you know how to do this?


Thanks,
jason
 
I almost added the code to cancel in my last post, but didn't think you wanted it. Here's how it word look:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.Dirty) Then
Select Case MsgBox("Changes have been made. Do You want to save the changes?", vbYesNoCancel & vbYesNo)
Case vbNo
Me.Undo
Case vbCancel
Cancel = True 'Do not update the record, don't discard the changes, stay on the same record
End Select
End Sub
 
Thanks again FancyPrairie,

"I almost added the code to cancel in my last post, but didn't think you wanted it."

I wasn't the original poster, but this helps me out a lot. I'm sure I'll use this bit of code quite a bit.

I'm had some mistakes in my last bit of code.
Here's the working code:
Code:
    If (Me.Dirty) Then
        Select Case MsgBox("Changes have been made.  Do You want to save the changes?", vbYesNoCancel)
        Case vbNo
            Me.Undo
        Case vbCancel
            Cancel = True 'Do not update the record, don't discard the changes, stay on the same record
        End Select
    End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top