Confirming a Record Change in a Form

Paula_NZ

New member
Local time
Today, 16:46
Joined
Dec 5, 2003
Messages
8
I want to add a function to a form that asks the user if they are sure they want to change the record before saving with a yes/no

Can anyone help me please.

:rolleyes:


Thank You that worked perfectly, how do I stop it going to the next record??
 
Last edited:
Use some code in the form's Before Update event to ask the user to confirm. But what do you want to happen if the user says "No, don't save the record?" Do you want to undo changes to the record, or do you just want the user to be thrown back into edit mode on the same record?

The code below will just put the user back into the same record without saving the changes:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intResponse As Integer

    intResponse = MsgBox("Update this record?", vbYesNo, "Confirm update")
    If intResponse = vbNo Then
        Cancel = True
    End If
End Sub

If you add a:
Me.Undo
before the Cancel=True, then it will also undo edits to the record.
 
dcx693 said:
Use some code in the form's Before Update event to ask the user to confirm. But what do you want to happen if the user says "No, don't save the record?" Do you want to undo changes to the record, or do you just want the user to be thrown back into edit mode on the same record?

The code below will just put the user back into the same record without saving the changes:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intResponse As Integer

    intResponse = MsgBox("Update this record?", vbYesNo, "Confirm update")
    If intResponse = vbNo Then
        Cancel = True
    End If
End Sub

If you add a:
Me.Undo
before the Cancel=True, then it will also undo edits to the record.

Hi ppl... I did a search on this forum for a confirm procedure before saving a record and found this article. Tested it and works just fine... but I have a form that has a auto-number field. This field keeps going on even if I answer no in the msgbox... is there any way to stop this from happening?
 
No. Jet assigns the new autonumber as soon as you type a single character into any form field. This is done to prevent duplication and minimize contention problems. You cannot affect the behaviour and it shouldn't matter anyway. An autonumber is simply a unique identifier for a record. It should have NO other meaning. Gaps should not present any problems since they could be caused by deleted records or by cancelled inserts.
 
Pat Hartman said:
No. Jet assigns the new autonumber as soon as you type a single character into any form field. This is done to prevent duplication and minimize contention problems. You cannot affect the behaviour and it shouldn't matter anyway. An autonumber is simply a unique identifier for a record. It should have NO other meaning. Gaps should not present any problems since they could be caused by deleted records or by cancelled inserts.

Ok! I WAS using the autonumber field for identification purpose (i´m just a rookie) but I realized that another field was probably better and with your explanation seems obvious that it is the best option. Thanks...
 
Use the autonumber as the primary key. If you have another unique identifier from some other source, create a unique index for it to prevent duplicates.
 

Users who are viewing this thread

Back
Top Bottom