I'm not going to pretend I know anything about inheritance, but I can
describe instancing for you. Also, all of this is based on older versions of
Access. If 2007 does not allow doing this anymore, then sorry to waste your
time. I believe I read about this in Access 97 Bible, but I've not looked at
Access books for some time so I don't know a currently recommendable one.
To keep this a simple explanation, let's say you have an order form
(frmOrder) with a textbox for OrderID.
In a standard module dim a form array with 3 elements, and a counter
variable.
Public FormArray(2) As Form
Public FormCounter As Integer
Create a function that creates an instance of the form and assigns it to one
of the elements, then increments the counter, so that we're not creating a
million of them. Note: when creating an instance, it does not become visible
until you tell it to be.
Function OpenNewOrderForm() As Boolean
If FormCounter > 2 Then Exit Function
Set FormArray(FormCounter) = New Form_frmOrder
FormArray(FormCounter).Visible = True
FormCounter = FormCounter + 1
End Function
In the frmOrder load event, assign a unique value to the OrderID, say using
the date and time, or something random so that you can tell a new form was
opened. Create a form, macro or use the debug window to run this function. A
new 'copy' of the form will open. When it does, the OrderID textbox will
contain a different value each time. You should now have three copies of
that form on screen (maybe hidden behind each other), and each can go along
it's own business, with it's own data, but all the events and other code
within it are the same. There is no need to call events, or try to manage
the form usage from some other module. Just think of it as having many forms
while only designing one.
As I said this example is only a simple one. Usually when I implement this,
I create a class for the type of form, and a collection to house them. For
instance, create a class module for Orders (collection) and one for Order.
This way you can create an Order class, assign it an instance of the order
form, assign properties like Form (so you can access the form itself - make
visible, setfocus etc.), OrderNumber, and whatever else. You'd then append
the Order object to the Orders collection and be able to manage all open
order forms like you do with the Forms collection, or the Fields collection.
The form would remain open as long as the object that created it existed in
the collection. Any functions that need to act on any given copy need only
refer to the collection and object, or if called form the form, pass a
reference of the form.
There are perhaps some drawbacks.
1) Using the filter and where arguments of the OpenForm method can't be
employed as you are not opening them this way. You can however affect
changes to the forms recordsource, filters and other properties before you
make it visible.
2) I've never tried doing this with forms that contain subforms - so I have
no idea how they would behave. Subforms are essentially instances themselves
so I think it would not be an issue, but I don't know for sure.
3) I've also never tried doing this with reports, but I kinda think they
should work almost the same way.
4) Using any code that use the Form Name as an argument may likely fail as
the same form is open numerous times. You would probably need to ensure that
the form reference, or some other uniquely identifying property is being
used (like hwnd).
Or did I just ramble on and not help?
Let me know.