[AccessD] Referencing forms as objects

Dan Waters df.waters at comcast.net
Mon Aug 1 09:08:32 CDT 2011


John - I like your discussion, but I'd also like to see your code.

Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Monday, August 01, 2011 8:50 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] Referencing forms as objects

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
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list