Here we go again. The attached document with embedded HSQL tries to nail down this problem in plain, stupid StarBasic with some configuration based on a hidden control named “OpenParameterForm”.
Having a pair of form documents, one loading the other with well defined parameters, you add a hidden control to the form navigator of the calling form, name it “OpenParameterForm” and add a semicolon separated list of configuration values, assign some form event, control event or mouse click to macro onFormAction, onControlAction or onMouseRelease respectively. The called form’s event “fill parameters” is assigned to macro “Substitute_Params”. That’s it. You don’t need to understand the code nor adjust the code to your specific needs. The StarBasic module can be moved to the global scope (“My Macros”) without any changes. You can use the exact same code with all your databases.
The loaded form document is linked to some parameter query such as SELECT * FROM "TBL" WHERE "Column" = :paramName.
This is an exception to the rule that we use to use parameter queries with subforms, because the parameters are supposed to be substituted by the parent form.
In this particular case, the macro code called by the calling form document stores criteria values in a global array variable and the routine assigned to the “fill parameters” event of the called form document reads those values from the variable to substitute the parameters.
How to set up the value of the hidden control “OpenParameterForm”? In case of one parameter, you enter ColumnName;Form Doc Name. “ColumnName” is the name of the column (not the control name) having the filter criterion in the calling form. “Form Doc Name” is the name of the form to be loaded. The form name may also be a hierarchical one if you store forms in folders, such as Folder Name/Form Doc Name.
My test document contains 3 form documents plus a folder of 2 form documents:
-
“Filter Data1” is the original form document with subforms, which does not use any macros. The filtering main form is bound to filter row 1. The filtered subform is bound to parameter query “ParamQuery” with 4 parameters.
-
“Filter Data2” is another instance of the same form document. The filtering main form is bound to filter row 2 in order to be independet from the other forms’ filter criteria (just for testing and debugging).
-
“Filtering Form1” is stripped down to the filtering main form and bound to the same filter row #1 as in “Filter Data1”.
-
In a subfolder “Param Forms” resides:
4.1. “Param Filter”, which is the filtered subform on a separate form document. It consumes the 4 filter criteria from “Filtering Form1” and shows the records filtered by the criteria entered into the calling form “Filtering Form1”. Missing criteria are ignored. Comparing the result set with the original form document “Filter Data1” (free of macros), the results should always be the same.
When you double-click the table control or when you click the big button, the current record is opened in
4.2. form document “Param Detail” based on the primary key “ID”.
Glitch: When using more than one parameter, the sequential order in which parameters are substituted is somewhat obscure. If your calling loaded form has more than one parameter, assign the form’s event “fill parameters” to the routine “Substitute_Params_DBG” and load the form. A message box pops up from where you can read the right order of parameters. Note the parameter names, assign “Substitute_Params” to the same event and note the corresponding 4 column names of the calling form to substitute the parameters.
For example, my “Param Filter” form is bound to query “ParamFilter” with 4 parameters. “Substitute_Params_DBG” reveals, that the parameters are queried in the order paramC;paramD1;paramD2;parmamP. The corresponding column names in the calling form are INT2;D1;D2;INT1 (as can be seen in the Master/Slave relation of the original “Filter Data” form).
The resulting configuration string to call “Param Filter” with 4 parameters is INT2;D1;D2;INT1;Param Forms/Param Filter, that is 4 columns in right order of param substitution plus hierarchical name of the form to be called.
The second sample, calling “Param Detail” from “Param Filter” uses the configuration string ID;Param Forms/Param Detail, loading “Param Forms/Param Filter” and substituting one parameter with the value of this form’s ID. This is the easy case with one column name and one document name.
OpenParamForms_Embedded_Macro.odb (466.7 KB)