Answered by:
pass parameter to a form using macro

Question
-
I wanted to open a sub from from main form on click and pass paramter from main form to sub form.
I can use VBA to pass parameters, but I tried to use macro to open a sub form.
I would like to know is it possible to pass parameters using macro Open Form?
If not, is it possible to mix open form using macro and pass paramters using VBA or just can not mix them, I hace to open form and pass parameters using VBA?
Your information and help is great appreciated,
Regards,
Sourises,
Wednesday, June 19, 2019 5:27 PM
Answers
-
Firstly I think you are using the term 'subform' incorrectly. A subform is a form which is embedded in a parent form, and is usually, but not necessarily, linked to the parent form by means of the subform control's LinkMasterFields and LinkChildFields properties. You appear to be referring to a form which is opened independently of the calling form.
As regards passing parameters, it depends what you mean by 'parameters'. If you mean criteria by which the form is filtered to a subset of rows, then the OpenForm macro action includes a WhereCondition argument. This is a string pression which can evaluate to True or False for each row in the form's RecordSource query or table, e.g. to filter an Orders form to orders by the customer currently selected in a calling form the expression would be along the lines of "CustomerID = " & [Forms]![Customers]![CustomerID].
If, on the other hand, by 'parameters' you mean values passed to the form which are then used by code in the form's module, the OpenForm macro action does not, as far as know, include an equivalent of the VBA OpenForm method's OpenArgs argument, so you would have to use VBA for this. If you want to pass multiple arguments, then take a look at Args.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.
This little demo file illustrates the use of a module, originally developed by Stuart McCall to pass multiple arguments, and later extended by me to include the ability to pass named arguments.
As you appear to be willing to use VBA, I'm puzzled by why you should want to use a macro at all for this.Ken Sheridan, Stafford, England
- Marked as answer by sourises Thursday, June 20, 2019 1:00 PM
Wednesday, June 19, 2019 10:34 PM
All replies
-
Firstly I think you are using the term 'subform' incorrectly. A subform is a form which is embedded in a parent form, and is usually, but not necessarily, linked to the parent form by means of the subform control's LinkMasterFields and LinkChildFields properties. You appear to be referring to a form which is opened independently of the calling form.
As regards passing parameters, it depends what you mean by 'parameters'. If you mean criteria by which the form is filtered to a subset of rows, then the OpenForm macro action includes a WhereCondition argument. This is a string pression which can evaluate to True or False for each row in the form's RecordSource query or table, e.g. to filter an Orders form to orders by the customer currently selected in a calling form the expression would be along the lines of "CustomerID = " & [Forms]![Customers]![CustomerID].
If, on the other hand, by 'parameters' you mean values passed to the form which are then used by code in the form's module, the OpenForm macro action does not, as far as know, include an equivalent of the VBA OpenForm method's OpenArgs argument, so you would have to use VBA for this. If you want to pass multiple arguments, then take a look at Args.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.
This little demo file illustrates the use of a module, originally developed by Stuart McCall to pass multiple arguments, and later extended by me to include the ability to pass named arguments.
As you appear to be willing to use VBA, I'm puzzled by why you should want to use a macro at all for this.Ken Sheridan, Stafford, England
- Marked as answer by sourises Thursday, June 20, 2019 1:00 PM
Wednesday, June 19, 2019 10:34 PM -
Thanks for the information and help,
The reason I wanted to use macro is that this application already use macro to open a form, I just wanted to know if it is possible to pass a value to a form just modify the macro instead of using VBA.
It looks like I need to use VBA to open a form and pass a value to a form.
Thanks a million again for the information and help,
Regards,
Sourises,
Thursday, June 20, 2019 1:00 PM