Undo not Available

BarryMK

4 strings are enough
Local time
Today, 03:11
Joined
Oct 15, 2002
Messages
1,350
The following code was fine in 97 but falls over in 2003 at the Undo command shown in red font. I get Undo not Available error

I've tried Me.Undo, Docmd.CancelEvent, Cancel =True. Any other ideas?

Private Sub cmdMove_Click()
On Error GoTo Err_cmdMove_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOwnerDetails"
stLinkCriteria = "[DogNumber]=" & Me![DogNumber]
'error check
If IsNull(Me.txtDogName) Then


MsgBox "Please get the dog's name and enter it. This will help the wardens if the dog is seized again", vbInformation, "Field cannot be left blank"
DoCmd.Undo
Me.cmdClose.SetFocus


End If
If IsNull(Me![StrayRef]) Then
MsgBox "Please select a dog from the list", vbInformation, "User error"
Else
'minimise current form
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
stLinkCriteria = "[DogNumber]=" & Me![DogNumber]
End If
Exit_cmdMove_Click:
Exit Sub

Err_cmdMove_Click:

Resume Exit_cmdMove_Click

End Sub
 
Hi Barry,
Tried to understand this from the Microsoft site, if it were me I would try including the formname

ie Me.formname.undo

or Me!formname.undo

Brian
 
Hi Barry,
The formatting is preserved and the code is much easier to read if you use the code tags. See if the change I made works.
Code:
Private Sub cmdMove_Click()
   On Error GoTo Err_cmdMove_Click

   Dim stDocName As String
   Dim stLinkCriteria As String

   stDocName = "frmOwnerDetails"
   stLinkCriteria = "[DogNumber]=" & Me![DogNumber]
   'error check
   If IsNull(Me.txtDogName) Then

      MsgBox "Please get the dog's name and enter it. " & _
             "This will help the wardens if the dog is seized again", _
             vbInformation, "Field cannot be left blank"
      [COLOR="Red"]If Me.Dirty Then Me.Undo[/COLOR]
      Me.cmdClose.SetFocus

   End If
   If IsNull(Me![StrayRef]) Then
      MsgBox "Please select a dog from the list", vbInformation, "User error"
   Else
      'minimise current form
      DoCmd.Close
      DoCmd.OpenForm stDocName, , , stLinkCriteria
      stLinkCriteria = "[DogNumber]=" & Me![DogNumber]
   End If
Exit_cmdMove_Click:
   Exit Sub

Err_cmdMove_Click:
   Resume Exit_cmdMove_Click

End Sub
 
RG,

The "stLinkCriteria" should be on top of the "DoCmd", else the criteria is blank.

Hi Barry,
DoCmd.OpenForm stDocName, , , stLinkCriteria
stLinkCriteria = "[DogNumber]=" & Me![DogNumber]
End Sub[/CODE]
 
I used RG's code with unclejoe's amendment and now it compiles. Thanks to all for your help.
 
Sorry to be a nuisance but Barry said that he tried
Me.Undo
and it did not work, so why does
If Me.Dirty Then Me.Undo
work as the only difference is that a check is being made to see if a modification has taken place, whereas in the first place it has been assumed (known?) to have taken place.

Please educate an old guy.

Brian
 
Brian - Are you looking for consistency in a Microsoft product?:rolleyes:
 
Brian,
Barry said it was reporting that Undo was not available on occasion. One reason for this message is that nothing was changed, hense my suggested change to the code. I didn't look down the code far enough to catch the change suggested by UncleJoe; good catch UncleJoe.
 
OK If I understand you it works if something had changed, fails if not, OK that makes some kind of sense, pity microsoft didn't point that out so that us thickies wouldn't think that it would just not undo if there was nothing to undo.

Thanks RG for your time.

Brian
 
You've probably noticed that each version of Access is a little less forgiving of some errors than the prior version. My guess is it is probably MS cleaning up some ambiguity that wasn't caught in the prior release.
 
I'm a bit out of the loop since I've been retired for18 months and maybe I should stop pretending I know something, but I enjoy solving problems and its more fun and satisfying than Sudoku.:)

Brian
 
Don't stop Brian. We're all just having fun here.
 
Brian,

The original code from OP was

DoCmd.Undo

That does not work at all. The correct code is,

DoCmd.RunCommand AcCmdUndo

Sometimes DoCmd has problems understanding which record or what to “Undo”. Worst cases are usually changing of the form’s properties in an event control.

The code given by RG is much better as it refers the current form’s properties, in this case the “Me”.

The “Me” refer to a current object “the current opened form” and “Dirty” refers to the form’s property = Dirty “True” or “False” and as well as “Undo”.

If you have a control in a Form that safe a record or cause the form’s “Dirty” property to False, then the “Undo” is useless. In this case, don’t use the “DoCmd” to undo a record.


Sorry to be a nuisance but Barry said that he tried
Me.Undo
and it did not work, so why does
If Me.Dirty Then Me.Undo
work as the only difference is that a check is being made to see if a modification has taken place, whereas in the first place it has been assumed (known?) to have taken place.
Please educate an old guy.
Brian
 

Users who are viewing this thread

Back
Top Bottom