Automatic Fill From One Form to Another.

  • Thread starter Thread starter Raj Patel
  • Start date Start date
R

Raj Patel

I know that people have posted similar questions, but I am unable to
find a answer to this particular issue.

I have a main form. This form contains a subform called Medical
Encounters. When you double-click on the Reason field of the Medical
Encounters subform a Search dialog pops up. You can search for valids
reasons here by keyword. Running a search results in a list of results
displayed in a listbox. If the user double-clicks on one of the
results in the list box I want the Search dialog to disappear and the
data from that listbox gets automatically filled into the Reason field
of the Medical Encounters subform the the user clicked on.

I realize this can be done by explicitly setting
Forms(MAIN_FORM_NAME)!sbfMedicalEncounters.Form.ActiveControl.Value =
blah, blah...

My problem is that Medical Encounters is NOT the only subform that
requires this functionality. I want to genericize the code such that I
can "figure out" from the Search dialog which field on the calling
form is active and fill in the appropriate field there.

Thanks.
 
-----Original Message-----
I know that people have posted similar questions, but I am unable to
find a answer to this particular issue.

I have a main form. This form contains a subform called Medical
Encounters. When you double-click on the Reason field of the Medical
Encounters subform a Search dialog pops up. You can search for valids
reasons here by keyword. Running a search results in a list of results
displayed in a listbox. If the user double-clicks on one of the
results in the list box I want the Search dialog to disappear and the
data from that listbox gets automatically filled into the Reason field
of the Medical Encounters subform the the user clicked on.

I realize this can be done by explicitly setting
Forms(MAIN_FORM_NAME)!
sbfMedicalEncounters.Form.ActiveControl.Value =
blah, blah...

My problem is that Medical Encounters is NOT the only subform that
requires this functionality. I want to genericize the code such that I
can "figure out" from the Search dialog which field on the calling
form is active and fill in the appropriate field there.

Thanks.
.
Hi Raj,
one option that you can try is to pass the form name and
control name to the search form as an open argument. Then
within the code of the search form you can reference the
open arguments for the form name and control name for the
calling form.

Use the following as an example...

'calling form
dim strOpenArgs as string

strOpenArgs=me.name & "," controlname

docmd.openform FormName:="frmSearch",
WindowMode:=acDialog, _
OpenArgs:=strOpenArgs

' search form
dim strArgs() as string
dim frm as frm
dim ctlas control

strArgs=split(me.openargs,",")
set frm = forms(strargs(0))
set ctl=frm.controls(strargs(1))

use either array or variables in your code

Luck
Jonathan
 
Back
Top