[AccessD] Form.Undo in Access 2000

jwcolby jwcolby at colbyconsulting.com
Mon Mar 23 14:39:34 CDT 2009


Many times I have needed a form undo in Access 2000 but it does not exist.  I just found this:

http://support.microsoft.com/kb/210326

I have implemented it in my framework, a minor modification to place most of the code in my clsFrm. 
Basically I placed the code INSIDE CheckUndo(frm as form) in a public mCheckUndo() method inside of 
my form class, then added a PrevBookmark in the header of the clsFrm.  this allows each form to 
track its own previous bookmark instead of a global variable which really only works for one form at 
a time.

I then placed the following code back into CheckUndo:

function CheckUndo(frm as form)
dim lclsFrm as dclsFrm	'Build a local variable to work with my clsFrm

	On Error resume next	'In case it isn't there yet
	'Grab the pointer to the clsFrm in the header of the form passed in
	set lclsFrm = frm.fclsFrm	
	
	'Call the public method of the class
	lclsfrm.mCheckUndo

	'Get rid of the pointer once finished
	set lclsFrm = nothing
	
end function

The code works by calling CheckUndo in a public module because a call to the function is placed in a 
n "unbound" text box's control source property.  Apparently Access refreshes this when the undo 
occurs in any control.

This is a good example of how a class can make something possible that is a PITA without a class. 
The code as seen in the knowledge base uses a public variable for the PreviousBookmark which makes 
it likely to fail when used for a set of forms such as two forms open at the same time.  Because I 
can create a private PreviousBookmark in m clsFrm header, I now have a place to store a unique copy 
for every form that uses clsFrm.

It seems to be working.  For anyone who has wanted undo processing in Access 2K this could be a 
godsend.  Access 2002 (XP) and above has a form Undo event so it is not necessary in those versions.

I have a case where the client wants a set of text boxes compared to one other text box, and a 
yellow color applied if the values differ.  I got that all working by using the OnExit of each of 
the text boxes.  Worked great EXCEPT that if the user exits the box and then does n "undo"... 
well... there was no way to go back and reapply the correct color (do the compare again).  With this 
undo I can now do that compare on an Undo.  I create an evUndo in my clsFrm and then sink that event 
back in my form where these text boxes reside.  In the event of the undo I go check this compare code.

Works exactly as you would expect.

-- 
John W. Colby
www.ColbyConsulting.com



More information about the AccessD mailing list