Simplify Coding

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
 
M

Marshall Barton

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)
. . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top