Several common ways to pass parameters between forms

Source: Internet
Author: User
Tags variables variable

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.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.