Revise the code please

George Too

Registered User.
Local time
Today, 12:27
Joined
Aug 12, 2002
Messages
198
Can anyone tell me why this code is not detecting the changes made in the bound subform?

If Me.ChildEditData.Form.Dirty Then
DoCmd.RunCommand acCmdUndo
Else
MsgBox "There were no modifications made to the current record.", vbInformation, "Invalid Undo"
End If

Thanks,
George
 
Which Event and which form are you using? It should be in the subform before update event, however if the record never gets dirtied your message box will not display
 
Ooops! It sits behind an On Click event of a button. The bound form sits on a tab control on an unbound "main" form.

This makes sense? I hope.

Thanks,
George
 
I'm guessin this is an UNDO button on the main "unbound" form.

If you perform changes in the subform then click the UNDO button the changes are saved on the subform and then the focus moves to the controls on the main form. You would not be able to undo any changes to the subform.
 
Ok, now I have this next code that I can put behind the After Update event of the subform (which actually works), but I don't know how I can lure the user out of the subform to trigger the event.

This is the code:

'see if this is a new record
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "@Do you wish to save the changes?"
strMsg = strMsg & "@Click Yes to Save or No to Discard changes."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If

Thanks,
George
 
You have to use the BeforeUpdate event
strMsg = "Data has changed."
strMsg = strMsg & "@Do you wish to save the changes?"
strMsg = strMsg & "@Click Yes to Save or No to Discard changes."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If
 

Users who are viewing this thread

Back
Top Bottom