So I've been working with a large access database recently and I've been thinking about the best way to begin refactoring it. One of the primary difficulties in refactoring, is most of the forms rely on data in other forms.
The way it is currently done is like so;
Form1
has a button on it called Cmd1
that opens up a new form (DoCmd.OpenForm "Form2"
) and pre-populates some controls on the form using Forms!Form2.Control = Me.Control
. When closing Form2
, data is returned to Form1
by calling Forms!Form1.Control = Me.Control
.
This presents a problem if I want to change either forms' names, or which form opens the popup form. It also requires both forms to be open, which you can't really rely on when you can't use modal popup forms because users want to be able to swap between forms.
I see 5 methods of passing values back and forth between forms, each with their problems, and I was wondering what was recommended.
- The method already in place as explained above.
- Using OpenArgs - makes lots of values difficult as you have to parse a string and is uni-directional.
- Using global variables - This would mean tons of variables in a random module and presents a scoping nightmare.
- Storing values to be passed between forms in a temporary table.
Maintaining a reference to the first form using
Public master As Form Private Sub Form_Load() Set master = Screen.ActiveForm Me.Control = master.Control End Sub
Which is kind of nice in that you can reference grandparent forms like
master.master.control
but could cause some major problems if a control on a parent form disappears in future.
So yeah, is there a recommended method?