[AccessD] Referencing forms as objects

jwcolby jwcolby at colbyconsulting.com
Mon Aug 1 08:50:15 CDT 2011


I needed an unbound form to open, allow a user to enter some data (a date and a comment).  If the 
user cancels then nothing happens, otherwise the user must enter both pieces and the date must be a 
valid date out in the future.  Thus the popup form has to do some validation.  If the user enters 
the date and comment then presses the Update button the data needs to be placed back in a pair of 
fields in the calling form.

Obviously there are a handful of ways this can be done.  The problem is that if the form is open 
modal popup, how do you transfer multiple data items back to the caller?  The code execution in the 
calling form stops as the form opens and doesn't continue until the modal form closes at which point 
the data is gone.

The method I selected was to open the form popup and modal and grab a reference to the form. Once I 
do that then I can treat the form like any other objects, and objects can raise events.  So I have 
the modal form declare that it is going to raise events, and in the button that closes the form  I 
raise an event passing the date and comment string to the event handler.  In the calling form I sink 
the event and capture the data.

In the calling form, dimension the form Withevents and sink the event in the calling form.  In the 
event handler take the data passed back and place it into the correct controls and set Dirty = false.

The takeaway here is that a form is a class.  Every class can raise events.  Every class can sink 
events.  So the modal form being opened can raise events and use that mechanism for transferring 
data.  The calling form can sink the events and use that mechanism for capturing the data.

Once you understand classes and raising / sinking events, this becomes a trivial exercise and an 
easy way to transfer multiple pieces of data back to the calling form.

-- 
John W. Colby
www.ColbyConsulting.com



More information about the AccessD mailing list