Simplify Coding

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have a question about how to simplify my code. The
current situation is that I am loading a form with values
from another form. Form 'frmInterventionFinder' is being
closed but needs to load different values into
Form 'frmGroupIntervention' before it closes. The code I
am using now works just fine, but seems to be a little too
repetitive for it's own good. Here is the code so far...


Case "Enter a New Session to the Intervention":
If Me.InterventionType = "Group" Then
DoCmd.OpenForm ("frmGroupIntervention")

Forms!frmGroupIntervention!ProjectName =
Forms!frmInterventionFinder.Column(1)
Forms!frmGroupIntervention!InterventionID =
Forms!frmInterventionFinder!InterventionList.Column(3)
Forms!frmGroupIntervention!ProjectCode =
Forms!frmInterventionFinder!ProjectCodeList
Forms!frmGroupIntervention!VendorCode =
Left(Forms!frmInterventionFinder!ProjectCodeList, 2)

and so on and so on...

This is done with many variables for one of 4 different
forms. Is there a way to condense the 'Forms!FormName'
for each? Any thoughts would be appreciated. Thank you
in advance.

Chris
 
Chris said:
I have a question about how to simplify my code. The
current situation is that I am loading a form with values
from another form. Form 'frmInterventionFinder' is being
closed but needs to load different values into
Form 'frmGroupIntervention' before it closes. The code I
am using now works just fine, but seems to be a little too
repetitive for it's own good. Here is the code so far...


Case "Enter a New Session to the Intervention":
If Me.InterventionType = "Group" Then
DoCmd.OpenForm ("frmGroupIntervention")

Forms!frmGroupIntervention!ProjectName =
Forms!frmInterventionFinder.Column(1)
Forms!frmGroupIntervention!InterventionID =
Forms!frmInterventionFinder!InterventionList.Column(3)
Forms!frmGroupIntervention!ProjectCode =
Forms!frmInterventionFinder!ProjectCodeList
Forms!frmGroupIntervention!VendorCode =
Left(Forms!frmInterventionFinder!ProjectCodeList, 2)

and so on and so on...

This is done with many variables for one of 4 different
forms. Is there a way to condense the 'Forms!FormName'
for each?

Depending on how much of this kind of code you have and the
pattern of controls being updated (e.g. always the same
controls or different controls, the same or different
columns in the combo box, etc), there are various approaches
that can be applied.

Based only on what you've posted above, I think you can at
least use something like this (AIR CODE):

DoCmd.OpenForm ("frmGroupIntervention")
Set frm = Forms("frmGroupIntervention")
frm!ProjectName = Me!youleftthisout.Column(1)
frm!InterventionID = Me!InterventionList.Column(3)
frm!ProjectCode = Me!ProjectCodeList
frm!VendorCode = Left(Me!ProjectCodeList, 2)
. . .
 
Back
Top