IF THEN ELSE CODE

  • Thread starter Thread starter NEOFYTOS
  • Start date Start date
N

NEOFYTOS

hello my name is Neofytos
i try to make a complex code and i need help.
i have the following code who separetly they are working properly.
my problem is to combine the following codes which are based all in the
field "edafoponiki morfi" in one concecutively code.

Private Sub EdafoponikiMorfi_AfterUpdate()
If Me.EdafoponikiMorfi.Value = 1 Or Me.EdafoponikiMorfi.Value = 2 Then
Me.StandOrigin.Enabled = True
Me.GrowthStage.Enabled = True
Me.MixtureType.Enabled = True
Me.F_UnderStoreySpecies_subform.Enabled = True
Me.F_TexnitiRecords_subform.Enabled = True
else
Me.StandOrigin.Enabled = False
Me.GrowthStage.Enabled = False
Me.MixtureType.Enabled = False
Me.F_UnderStoreySpecies_subform.Enabled = False
Me.F_TexnitiRecords_subform.Enabled = False




If Me.EdafoponikiMorfi.Value = 9 Then
Me.Platos.Enabled = True
Else
Me.Platos.Enabled = False




If Me.EdafoponikiMorfi.Value = 8 Then
Me.EdafoponikiDescription.Enabled = True
Else
Me.EdafoponikiDescription.Enabled = False




If Me.EdafoponikiMorfi.Value = 1 Or Me.EdafoponikiMorfi.Value = 2 Or
Me.EdafoponikiMorfi.Value = 3 Then
Me.F_ForestSpecies_subform.Enabled = True
Else
Me.F_ForestSpecies_subform.Enabled = False
End If


it is important for me to know the procedure,rules and steps
that i have to follow in order to write these complex codes

i am sure for your help
-- best regards
neofytos
THANK YOU
 
Hi,
code looks ok in general, do you get any errors? you have to add several end
if. You can try the following:

If Me.EdafoponikiMorfi.Value = 1 Or Me.EdafoponikiMorfi.Value = 2 Then
Me.StandOrigin.Enabled = True
Me.GrowthStage.Enabled = True
Me.MixtureType.Enabled = True
Me.F_UnderStoreySpecies_subform.Enabled = True
Me.F_TexnitiRecords_subform.Enabled = True
else
Me.StandOrigin.Enabled = False
Me.GrowthStage.Enabled = False
Me.MixtureType.Enabled = False
Me.F_UnderStoreySpecies_subform.Enabled = False
Me.F_TexnitiRecords_subform.Enabled = False
end if



If Me.EdafoponikiMorfi.Value = 9 Then
Me.Platos.Enabled = True
Else
Me.Platos.Enabled = False
end if



If Me.EdafoponikiMorfi.Value = 8 Then
Me.EdafoponikiDescription.Enabled = True
Else
Me.EdafoponikiDescription.Enabled = False
end if


If Me.EdafoponikiMorfi.Value = 1 Or Me.EdafoponikiMorfi.Value = 2 Or
Me.EdafoponikiMorfi.Value = 3 Then
Me.F_ForestSpecies_subform.Enabled = True
Else
Me.F_ForestSpecies_subform.Enabled = False
End If

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
Hi,

I would use something like the CASE statement:

SELECT CASE Me.EdafoponikiMorfi.Value
CASE 1, 2, 3
' Do something here
If Me.EdafoponikiMorfi.Value = 1 Or Me.EdafoponikiMorfi.Value = 2
Then
Me.StandOrigin.Enabled = True
Me.GrowthStage.Enabled = True
Me.MixtureType.Enabled = True
Me.F_UnderStoreySpecies_subform.Enabled = True
Me.F_TexnitiRecords_subform.Enabled = True
Me.F_ForestSpecies_subform.Enabled = True

Me.F_ForestSpecies_subform.Enabled = True

CASE 8
' Do something here
Me.EdafoponikiDescription.Enabled = True
CASE 9
' Do something here
Me.Platos.Enabled = True
CASE ELSE
' Do something here
Me.StandOrigin.Enabled = False
Me.GrowthStage.Enabled = False
Me.MixtureType.Enabled = False
Me.F_UnderStoreySpecies_subform.Enabled = False
Me.F_TexnitiRecords_subform.Enabled = False

Me.F_ForestSpecies_subform.Enabled = False

Me.Platos.Enabled = False

Me.EdafoponikiDescription.Enabled = False

END SELECT

You can nest If statements within the CASE statements to further control
program flow.
Also don't forget you can use If ElseIf Else statements.

IF Me.EdafoponikiMorfi.Value=1 OR Me.EdafoponikiMorfi.Value=2 OR
Me.EdafoponikiMorfi.Value=3 THEN
' Do something here
ELSEIF Me.EdafoponikiDescription.Enabled = 8
' Do something here
ELSEIF Me.EdafoponikiDescription.Enabled = 9
' Do something here
ELSE
' Do something here
ENDIF

You will need to make the above examples fit what you need as they are for
illustration only.

Regards
 
Back
Top