Yes or No question on dirty

G

Guest

I would like to have a message pop up when data is changed in a form with the
action to follow.
I know it has something to do with the property of "On dirty"
If any control is changed in the "Employee" form is made, I should receive a
message stating " You have updated information on this record. Do you want to
save it?" The answer of "Yes" or "No" is selected and the action should
happen with an exiting statment of "Update has been saved" or "update has not
been saved"
 
G

Guest

Use the form Before Update event:

If Msgbox("Data Has Changed - Do You Want to Update this Record", _
vbQuestion + vbYesNo) = vbNo Then
MsgBox "Record Not Updated"
Cancel = True
End If

Now, we don't want to put the Updated message here, because the update has
not occurred. That you should put in the After Update event. You don't need
a question with it. Just be sure it is placed so it will not show if an
error occurs:

Private Sub Form_BeforeUpdate()

On Error GoTo NoUpdateError

MsgBox "Record Updated"

Exit Sub

NotUpdateError:

MsgBox Err.Number & " " & Err.Description
End Sub
 
G

Guest

I have inserted code stated in update event but receive this statment when
entering "NO" in text box. First I receive "Record Not Updated" then another
message box that states after clicking on the "OK" on "Record not updated";
"You can't go to the specified record" and it will not let me go to the next
record until I enter "Yes" then it accept changes and allows me to go to the
next record
other wise it loops the statments
Where do I enter the statment listed below?
I am very confused on this.
 
G

Guest

I made a couple of mistakes, sorry.
First, I left out a line in the before update if the user answers no.
Should be:

If Msgbox("Data Has Changed - Do You Want to Update this Record", _
vbQuestion + vbYesNo) = vbNo Then
MsgBox "Record Not Updated"
Cancel = True
Me.Undo
End If

The Undo will allow you to move to another record.

The other code should be in the After Update.

Private Sub Form_AfterUpdate()
On Error GoTo NoUpdateError

MsgBox "Record Updated"

Exit Sub
NotUpdateError:

MsgBox Err.Number & " " & Err.Description
End Sub
 
G

Guest

Thanks, I am allowed to move to the next record when I answer "NO" but I
still receive the message box "you can't go to the Specified record" and when
entereing the code in the Private Sub Form_AfterUpdate() when I answer "Yes"
it goes to the compiler highliting the "On error got noupdateerror" with a
message box stating "Label no defined"
 
G

Guest

The label is defined in the code I posted, but again, I have a syntax error.
My brain was only at about 40% power yesterday, sorry

Private Sub Form_AfterUpdate()
On Error GoTo NotUpdateError <-reference to label

MsgBox "Record Updated"

Exit Sub
NotUpdateError: <- label (must have colon)
 
G

Guest

Thanks! That did the trick.

Klatuu said:
The label is defined in the code I posted, but again, I have a syntax error.
My brain was only at about 40% power yesterday, sorry

Private Sub Form_AfterUpdate()
On Error GoTo NotUpdateError <-reference to label

MsgBox "Record Updated"

Exit Sub
NotUpdateError: <- label (must have colon)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top