Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Access: passing parameters from one access form to another

Tags:

ms-access

I've got a form and a button on it. I would like to open another form on a button click with a parameter passed from the parent form to the child form (child form's RecordSource has parameters). How can I do it?

like image 578
agnieszka Avatar asked Dec 30 '22 15:12

agnieszka


2 Answers

You can refer to any property of the calling form by reference to the form's object. I will not use the ! notation for form's properties (I hate it). so if you want to inherit:

a form's control value:

forms(parentFormName).controls(controlName).value 

a form's recordset field value:

forms(parentFormName).recordset.fields(fieldName).value

The recordset turnaround is particularly useful when accessing id's (guid) values. You cannot read these values through form's controls, but you can access them throught the corresponding field in the recordset. If you have a combobox on a form containing a guid field, please compare the following:

 screen.activeForm.controls(myComboControlName).value

and

 screen.activeForm.recordset.fields(myComboControlName).value
like image 196
Philippe Grondier Avatar answered Jan 10 '23 23:01

Philippe Grondier


If the parent form is open, you can do the following

Forms!MyParentForm!myPublicVariableOfParentForm

There could be other ways, whereby you can call a method on the child form with a parameter from the parent form. Remember the control will likely need focus before being manipulated.

like image 26
shahkalpesh Avatar answered Jan 11 '23 01:01

shahkalpesh