In practical development applications, it is often necessary to pass parameters between forms. Several commonly used parameter transfer methods are as follows:
1. Using OpenArgs
Use the following statement in the calling form:
DoCmd.OpenForm "called form",,,,,, "parameter value"
Use Me.openargs on the called form to get the arguments passed over
2. Using Global variables
Set a global variable first, for example: Gstrpara,
Public Gstrpara As String
Pass parameter values to this global variable before calling
Gstrpara= "parameter Value"
DoCmd.OpenForm "called form"
Use Gstrpara in the called form to get the arguments passed over
3. Using the tag tag
Place the parameter you want to pass in the tag tag of the calling form
Call forms (called forms) in the called form. Tag to get the value of the parameter
4. Using module variables
Set a public module variable in the calling form Mstrpara
The arguments to be passed are placed in the Mstrpara variable of the calling form
By calling forms (called forms) in the called form. Mstrpara to get the value of the parameter
5. Direct access
If the parameter comes from a control that invokes the form, it can also be called directly
The value of the control that invokes the form is referenced directly in the form being called: forms (called form). Control name. Value
6. Multiple parameter Passes
If you need to pass more than one argument, you can merge the parameters into one variable (separated by the specified symbol), and then split the variables in the called form to achieve the effect of passing multiple parameters.
However, since generally passing two parameters, most of them are variables, one is the form itself,
So my common method is also a more practical method is:
Use the following statement in the calling form:
DoCmd.OpenForm "called form",,,,,, "parameter value"
Instead, set a module variable in the called form MFRMSRC
Set in the open or Load event of the called form
Set mfrmsrc= Screen.activeform
The mfrmsrc then points to the original calling form (because the form that is activated on the screen is the original form before the form is fully loaded)
Using MFRMSRC, you can get all the controls on the form and the associated values, and you don't need to know the name of the original form in advance, which is more versatile.
There should be more and better parameter transfer methods, not one of the examples, but also hope that we discuss this topic, related replies please comment.